当将鼠标悬停在子元素上时,是否可以删除CSS悬停叠加层的一部分?

时间:2015-03-02 23:39:04

标签: javascript jquery html css overlay

我使用CSS Image Map Generator伪造了一张图片地图。当用户将鼠标悬停在外部图像上时,我希望整个图像变暗,并在热点周围出现边框。当他们将鼠标悬停在热点上时,我希望该热点能够被点燃。这甚至可能吗?

  1. 此图片显示了一个包含产品界面图像的框 - 为了安全起见 - 在其中删除(通过CSS background-image)。用户现在没有悬停在它上面。没有可见的热点,没有图像叠加。
  2. 此图显示用户悬停在“外部”图像的一部分上。该图像具有透明覆盖(黑色,45%不透明度),图像地图热点可见。
  3. 此图显示用户将鼠标悬停在热点上。
  4. un-hover outer-hover enter image description here

    当它们悬停在热点上时,我希望删除父悬停叠加层的热点区域。那可能吗?我会接受任何可证明的解决方案。 Javascript / jQuery很好。

    HTML:

    <div class="map_image">
              <div class="overlay">
                    <a class="map_link" id="map_link_0" href="dp"></a>
                    <a class="map_link" id="map_link_1" href="a"></a>
                    <a class="map_link" id="map_link_2" href="s"></a>
                    <a class="map_link" id="map_link_3" href="ab"></a>
                    <a class="map_link" id="map_link_4" href="ch"></a>
                    <a class="map_link" id="map_link_5" href="ai"></a>
                    <a class="map_link" id="map_link_6" href="al"></a>
                    <a class="map_link" id="map_link_7" href="as"></a>
                    <a class="map_link" id="map_link_8" href="o"></a>
                    <a class="map_link" id="map_link_9" href="pc"></a>
                    <a class="map_link" id="map_link_10" href="wi"></a>
                    <a class="map_link" id="map_link_11" href="c"></a>
                    <a class="map_link" id="map_link_12" href="pq"></a>
              </div>
    </div>
    

    CSS:

    .map_image { display: block; width: 200px; height: 596px; position: relative; border: 1px solid gray; }
    
    .map_image .map_link { display: block; position: absolute; text-indent: -999em; overflow: hidden; border: 2px solid orange; }
    
    .map_image #map_link_0 { top: 106px; left: 20px; }
    .map_image #map_link_1 { top: 106px; left: 79px; }
    .map_image #map_link_2 { top: 106px; left: 138px; }
    .map_image #map_link_3 { top: 160px; left: 20px; }
    .map_image #map_link_4 { top: 160px; left: 79px; }
    .map_image #map_link_5 { top: 160px; left: 138px; }
    .map_image #map_link_6 { width: 30px; height: 27px; top: 0px; right: 0px; }
    .map_image #map_link_7 { width: 196px; height: 27px; top: 33px; left: 0px; }
    .map_image #map_link_8 { bottom: 2px; left: 6px; }
    .map_image #map_link_9 { bottom: 2px; left: 43px; }
    .map_image #map_link_10 { bottom: 2px; left: 80px; }
    .map_image #map_link_11 { bottom: 2px; left: 117px; }
    .map_image #map_link_12 { bottom: 2px; left: 155px; }
    
    #map_link_8, #map_link_9, #map_link_10, #map_link_11, #map_link_12 { height: 30px; width: 30px;}
    
    #map_link_0, #map_link_1, #map_link_2, #map_link_3, #map_link_4, #map_link_5 { width: 37px; height: 37px; border-radius: 5px; }
    
    .overlay {  background:rgba(0,0,0,.45); width: 200px; height: 596px; opacity:0; -webkit-transition: opacity .25s ease; -moz-transition: opacity .25s ease;}
    
    .map_image:hover .overlay { opacity:1; }
    

3 个答案:

答案 0 :(得分:1)

CBroe的评论就是诀窍。在悬停链接元素时,将背景设置为原始图像,充分定位以显示链接区域后面的原始位置(考虑边框大小)。

这里有JSFiddle的结果(显然发布Codepen是nono)。

&#13;
&#13;
.map_image {
    display: block;
    width: 200px;
    height: 596px;
    position: relative;
    background: url('https://media.licdn.com/mpr/mpr/p/6/005/086/004/186c3f8.jpg') top left no-repeat;
    border: 1px solid gray;
}
.map_image .map_link {
    display: block;
    position: absolute;
    text-indent: -999em;
    overflow: hidden;
    border: 2px solid orange;
}
.map_image #map_link_0 {
    top: 106px;
    left: 20px;
}
.map_image #map_link_1 {
    top: 106px;
    left: 79px;
}
.map_image #map_link_2 {
    top: 106px;
    left: 138px;
}
.map_image #map_link_3 {
    top: 160px;
    left: 20px;
}
.map_image #map_link_4 {
    top: 160px;
    left: 79px;
}
.map_image #map_link_5 {
    top: 160px;
    left: 138px;
}
.map_image #map_link_6 {
    width: 30px;
    height: 27px;
    top: 0px;
    right: 0px;
}
.map_image #map_link_7 {
    width: 196px;
    height: 27px;
    top: 33px;
    left: 0px;
}
.map_image #map_link_8 {
    bottom: 2px;
    left: 6px;
}
.map_image #map_link_9 {
    bottom: 2px;
    left: 43px;
}
.map_image #map_link_10 {
    bottom: 2px;
    left: 80px;
}
.map_image #map_link_11 {
    bottom: 2px;
    left: 117px;
}
.map_image #map_link_12 {
    bottom: 2px;
    left: 155px;
}
#map_link_8, #map_link_9, #map_link_10, #map_link_11, #map_link_12 {
    height: 30px;
    width: 30px;
}
#map_link_0, #map_link_1, #map_link_2, #map_link_3, #map_link_4, #map_link_5 {
    width: 37px;
    height: 37px;
    border-radius: 5px;
}
.overlay {
    background:rgba(0, 0, 0, .45);
    width: 200px;
    height: 596px;
    opacity:0;
    -webkit-transition: opacity .25s ease;
    -moz-transition: all .25s ease;
}
.map_image:hover .overlay {
    opacity:1;
}
#map_link_0:hover {
    background: url('https://media.licdn.com/mpr/mpr/p/6/005/086/004/186c3f8.jpg') -22px -108px, top left no-repeat;
}
#map_link_1:hover {
    background: url('https://media.licdn.com/mpr/mpr/p/6/005/086/004/186c3f8.jpg') -81px -108px, top left no-repeat;
}
#map_link_2:hover {
    background: url('https://media.licdn.com/mpr/mpr/p/6/005/086/004/186c3f8.jpg') -140px -108px, top left no-repeat;
}
#map_link_3:hover {
    background: url('https://media.licdn.com/mpr/mpr/p/6/005/086/004/186c3f8.jpg') -22px -162px, top left no-repeat;
}
#map_link_4:hover {
    background: url('https://media.licdn.com/mpr/mpr/p/6/005/086/004/186c3f8.jpg') -81px -162px, top left no-repeat;
}
#map_link_5:hover {
    background: url('https://media.licdn.com/mpr/mpr/p/6/005/086/004/186c3f8.jpg') -140px -162px, top left no-repeat;
}
&#13;
<h1>Interface</h1>

<p>Hover over the image below for cool stuff.</p>
<div class="map_image">
    <div class="overlay">
    <a class="map_link" id="map_link_0" href="pd"></a>
	<a class="map_link" id="map_link_1" href="a"></a>
	<a class="map_link" id="map_link_2" href="s"></a>
	<a class="map_link" id="map_link_3" href="ab"></a>
	<a class="map_link" id="map_link_4" href="ch"></a>
	<a class="map_link" id="map_link_5" href="ai"></a>
	<a class="map_link" id="map_link_6" href="al"></a>
	<a class="map_link" id="map_link_7" href="as"></a>
	<a class="map_link" id="map_link_8" href="o"></a>
	<a class="map_link" id="map_link_9" href="pc"></a>
	<a class="map_link" id="map_link_10" href="wi"></a>
	<a class="map_link" id="map_link_11" href="c"></a>
	<a class="map_link" id="map_link_12" href="pq"></a>
    </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

因此,如果我理解您的问题,您希望在用户将鼠标悬停在特定元素上时删除橙色边框?如果是这样,你可以通过像这样更新你的CSS来做到这一点:

.map_image .map_link:hover {
     border: 2px solid transparent;
}

启动hover后,边框仍为2px且不可见。

答案 2 :(得分:0)

尝试

$(".overlay .map_link")
.on({
    mouseover: function(e) {      
        $(this).css("background-color", "#fff")
    }
  , mouseleave:function(e) {
        $(this).css("background","transparent")
    }
})

jsfiddle http://jsfiddle.net/05q8zLsr/3/

$(".overlay .map_link")
.on({
mouseover: function(e) {      
    $(this).css("background-color", "#fff")
}
  , mouseleave:function(e) {
    $(this).css("background","transparent")
}
})
.map_image { display: block; width: 200px; height: 596px; position: relative; border: 1px solid gray; }

.map_image .map_link { display: block; position: absolute; text-indent: -999em; overflow: hidden; border: 2px solid orange; }

.map_image #map_link_0 { top: 106px; left: 20px; }
.map_image #map_link_1 { top: 106px; left: 79px; }
.map_image #map_link_2 { top: 106px; left: 138px; }
.map_image #map_link_3 { top: 160px; left: 20px; }
.map_image #map_link_4 { top: 160px; left: 79px; }
.map_image #map_link_5 { top: 160px; left: 138px; }
.map_image #map_link_6 { width: 30px; height: 27px; top: 0px; right: 0px; }
.map_image #map_link_7 { width: 196px; height: 27px; top: 33px; left: 0px; }
.map_image #map_link_8 { bottom: 2px; left: 6px; }
.map_image #map_link_9 { bottom: 2px; left: 43px; }
.map_image #map_link_10 { bottom: 2px; left: 80px; }
.map_image #map_link_11 { bottom: 2px; left: 117px; }
.map_image #map_link_12 { bottom: 2px; left: 155px; }

#map_link_8, #map_link_9, #map_link_10, #map_link_11, #map_link_12 { height: 30px; width: 30px;}
	
#map_link_0, #map_link_1, #map_link_2, #map_link_3, #map_link_4, #map_link_5 { width: 37px; height: 37px; border-radius: 5px; }

.overlay {  background:rgba(0,0,0,.45); width: 200px; height: 596px; opacity:0; -webkit-transition: opacity .25s ease; -moz-transition: opacity .25s ease;}

.map_image:hover .overlay { opacity:1; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h1>Interface</h1>
<p>Hover over the image below for stuff.</p>
<div class="map_image">
			  <div class="overlay">
				    <a class="map_link" id="map_link_0" href="dp"></a>
				    <a class="map_link" id="map_link_1" href="a"></a>
				    <a class="map_link" id="map_link_2" href="s"></a>
				    <a class="map_link" id="map_link_3" href="ab"></a>
				    <a class="map_link" id="map_link_4" href="ch"></a>
				    <a class="map_link" id="map_link_5" href="ai"></a>
				    <a class="map_link" id="map_link_6" href="al"></a>
				    <a class="map_link" id="map_link_7" href="as"></a>
				    <a class="map_link" id="map_link_8" href="o"></a>
				    <a class="map_link" id="map_link_9" href="pc"></a>
				    <a class="map_link" id="map_link_10" href="wi"></a>
				    <a class="map_link" id="map_link_11" href="c"></a>
				    <a class="map_link" id="map_link_12" href="pq"></a>
			  </div>
</div>