【发布时间】:2013-06-16 20:48:12
【问题描述】:
我正在开发一款需要大地图的游戏。我所做的是在 z-index 为 1 的可滚动 div (scrollWindow) 的背景中设置大的 12k x 12k 像素图。
稍后,Ajax 调用返回一些 JSON 数据,这些数据在大型背景地图中添加了许多类 (City_Palace)。元素的 z-index 为 9。
我还设置了几个鼠标悬停事件,这些事件根据光标是在背景中的地图上还是在其上绘制的城市之一上执行不同的操作。然而,即使城市的 z-index 远高于主窗口的 z-index,该事件也不会因为城市鼠标悬停而触发,因为可滚动窗口位于“顶部”。
当涉及到鼠标事件时,jquery 使用什么标准来确定哪个 div 位于“顶部”?好像z-index不是这样的。
这里有一些代码:
CSS:
#scrollWindow {
width: 1970px;
height: 900px;
overflow: scroll;
border: solid black 3px;
position: absolute;
z-index:1;
}
.City_Palace {
height: 20px;
width: 20px;
position: absolute;
z-index: 9;
background-image: url("../Images/City_Palace.png");
background-size: 100% 100%;
}
jquery:
$('.City_Palace').mouseover(function() {
alert("city classes on top");
});
$("#scrollWindow").mousemove(function(e){
alert("scroll window on top");
});
HTML 的生成方式如下:
<div id="scrollWindow" class="ui-widget-content" style="width: 2105px;">
<img id="img" src="../Images/fullSizeMap.png">
<div class="City_Palace" value="coast" style="left: 780px; top: 540px;"></div>
</div>
我猜想不知何故,父子关系覆盖了 z-index。关于如何解决这个问题的任何建议?谢谢!
【问题讨论】: