我是javascript的初学者。
这是我的javascript:在地图'demo'中,代码将所有区域元素推送到数组elementPositions中。当用户将鼠标悬停在某个区域元素上时,它会被推入数组hoveredElements。然后对于hoveredElements中的每个area元素,overlay id标签显示,我也想要显示area元素(一个矩形)。我试过'$(this).show()'但这不起作用......
这是一个典型的区域元素:
<map name="demo" id="demo">
<area shape="rect" coords="400,400,500,499" href="#" id="r6067" alt="r6067">
</map>
<div class= "cont" style="display:none" id="overlayr6067"> mdtBIL1C09 </div>
我接受了Nikolay在下面重构我的javascript,这是我在jsfiddle中的代码进行中:https://jsfiddle.net/sfs1926/wacd5bv5/1/
答案 0 :(得分:1)
您可以使用hoveredElements[ih].element.show()
。
或item.element.show();
如果您按照我的重构代码进行操作,可以使用if ( $('#demo').length >0 ) {
var elementPositions = []; // didn't find it declared in your code
$('#demo area').each(function() {
var offset = this.coords,
coordarray = offset.split(","),
left = coordarray[0],
top = coordarray[1],
right = coordarray[2],
bottom = coordarray[3],
id = this.id,
hoveredElements = [];
elementPositions.push({
element: $(this),
top: top,
bottom: bottom,
left: left,
right: right,
id: id,
});
$("body").mousemove(function(e) {
/*
for (var ih = 0; ih < hoveredElements.length; ih++) { //for loop over all hovered elements
var id = hoveredElements[ih].id;
$('#overlay' + id).hide();
}
*/
hoveredElements.forEach( function(item) {
item.overlay.hide();
});
hoveredElements = [];
var xPosition = e.pageX;
var yPosition = e.pageY;
for (var ie = 0; ie < elementPositions.length; ie++) {
var test = elementPositions[ie].id;
if (xPosition >= elementPositions[ie].left &&
xPosition <= elementPositions[ie].right &&
yPosition >= elementPositions[ie].top &&
yPosition <= elementPositions[ie].bottom) {
// The mouse is within the element's boundaries
hoveredElements.push({
element: elementPositions[ie].element,
overlay: $('#overlay' + test), // store overlay too
id: test
});
}
} //end of for loop over all elements
/*
for (var ih = 0; ih < hoveredElements.length; ih++) { //for loop over all hovered elements
var id = hoveredElements[ih].id;
$('#overlay' + id).show();
$(this).show(); // ???
}
*/
hoveredElements.forEach( function(item) {
item.overlay.show();
item.element.show();
});
});
});
}
。
Dim temp As String
Dim rowlast As Integer
Dim page As Integer
rowlast = Sheets("Data").Cells(Rows.Count, "A").End(xlUp).Row
'MsgBox WorksheetFunction.RoundUp((rowlast - 1) / 4, 0)
For page = 1 To WorksheetFunction.RoundUp((rowlast - 1) / 4, 0)
'Msgbox for first entry in current page
Label1.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2, 1)
MsgBox Label1.Caption
Label3.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 1, 1)
Label5.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 2, 1)
Label7.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 3, 1)
Label2.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2, 2)
Label4.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 1, 2)
Label6.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 2, 2)
Label8.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 3, 2)
Label9.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2, 3)
Label10.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 1, 3)
Label11.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 2, 3)
Label12.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 3, 3)
Label13.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 3, 5)
Label14.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 3, 5)
Label15.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 3, 5)
Label16.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 3, 5)
Label17.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 3, 4)
Label18.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 3, 4)
Label19.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 3, 4)
Label20.Caption = Sheets("Data").Cells(((page - 1) * 4) + 2 + 3, 4)
'MsgBox "OK"
Sheets("Card Print").PrintOut
Next page