【发布时间】:2016-05-31 21:35:19
【问题描述】:
我有一个类似的结构:一个带有image、image map 和overlays 的容器。它应该像这样工作:当悬停在 area-元素上时,应该会显示一个叠加层(在同一位置)。
但我无法让它工作。似乎覆盖层总是挡住hover 的区域。
我尝试过的:
-
absolute和relative定位在image和map甚至areas - 将 DOM 中元素的顺序更改为 img > overlay > map
-
z-indexes的所有变体
我该如何解决这个问题?
注意:我不能用pointer-events: none来解决它,因为我需要支持IE10。
这是一个简化的例子:
HTML
<div class="container">
<img src="//placehold.it/400" usemap="#map">
<map name="map">
<area shape="rect" coords="0, 0, 200, 200" href="">
</map>
<div class="overlay"></div>
</div>
CSS
.container {
position: relative;
width: 400px;
height: 400px;
}
map {
position: relative;
z-index: 1000;
}
.overlay {
opacity: 0;
position: absolute;
z-index: 500;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
}
.overlay.active {
opacity: 1;
}
JavaScript
$('areas').hover(
function() {
var e = $(this);
$('.overlay').addClass('active');
consoloe.log("enter");
},
function() {
$('.overlay').removeClass('active');
consoloe.log("enter");
}
);
jsFiddle
【问题讨论】: