简体   繁体   English

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

[英]Is it possible to remove a portion of a CSS hover overlay when hovering over a child element?

I am faking an image map by using CSS Image Map Generator . 我正在使用CSS Image Map Generator伪造图像地图。 When the user hovers over the outer image, I want the entire image to darken a little and have a border appear around the hot spots. 当用户将鼠标悬停在外部图像上时,我希望整个图像变暗一点,并在热点周围出现边框。 When they hover over a hotspot, I want that hotspot to be undarkened. 当他们将鼠标悬停在某个热点上时,我希望该热点不会消失。 Is this even possible? 这有可能吗?

  1. This image shows a box containing an image of a product interface - removed for security purposes - inside it (via CSS background-image). 此图像显示了一个包含产品界面图像的框-为了安全起见,在其中删除了该界面(通过CSS背景图像)。 The user is not hovering over it right now. 用户现在没有将鼠标悬停在上面。 No visible hotspots, no image overlay. 没有可见的热点,没有图像叠加。
  2. This image shows a user hovering over a portion of the "outer" image. 此图像显示用户将鼠标悬停在“外部”图像的一部分上。 The image has a transparent overlay (black, 45% opacity) applied and the image map hotspots become visible. 图像具有透明的覆盖层(黑色,不透明度为45%),并且图像地图热点变得可见。
  3. This image shows a user hovering over a hotspot. 此图像显示用户将鼠标悬停在热点上。

未悬停外,悬停在此处输入图片说明

When they hover over the hotspot, I'd like the hotspot area of the parent hover overlay to be removed. 当他们将鼠标悬停在热点上时,我希望将父悬停叠加层的热点区域删除。 Is that possible? 那可能吗? I'll accept any demonstrable solution. 我将接受任何可证明的解决方案。 Javascript/jQuery is fine. Javascript / jQuery很好。

HTML: 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: 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; }

CBroe's comment is what did the trick. CBroe的评论是解决问题的方法。 On hover of the link elements, set the background to be the original image, positioned adequately to show the original location behind the link area (accounting for border sizes). 在链接元素上悬停时,将背景设置为原始图像,并放置在适当位置以显示链接区域后面的原始位置(考虑边框大小)。

Here's a JSFiddle with the result (apparently posting Codepen is a nono). 这是一个带有结果的JSFiddle (显然,发布Codepen是一个nono)。

 .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; } 
 <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> 

So if I understand your question you want the orange border removed when the user hovers over the specific element? 因此,如果我理解您的问题,您希望在用户将鼠标悬停在特定元素上时删除橙色边框吗? If so you can do that by updating your CSS like this: 如果是这样,您可以通过更新CSS来做到这一点:

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

Once the hover is initiated the border will still be 2px and invisible. hover启动后,边框仍将为2px并且不可见。

Try 尝试

$(".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/ 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery:在主元素上悬停时如何悬停子元素的子元素 - jQuery: How to hover a child of child element when hovering on the main element jQuery-悬停在另一个元素上时触发悬停 - jquery - trigger hover on one element when hovering over another 将鼠标悬停在绝对定位的重叠元素上时,暂停悬停脚本 - Pausing hover script, when hovering over overlapping, absolutely positioned element 悬停在另一个元素上时如何触发悬停 - How to trigger hover when hovering over another element 悬停在另一个元素上时保持Li的悬停状态 - Keeping the Hover State of a Li When Hovering Over Another Element 在悬停时隐藏背景图层,将鼠标悬停在上方时会收起 <p> 元件 - Hide background layer on hover, reapers when hovering over <p> element 仅在不将鼠标悬停在某些元素上时执行hover() - Only execute hover() when NOT hovering over certain element 悬停在子元素上时未触发 Bootstrap 5 工具提示 - Bootstrap 5 Tooltip not triggered when hovering over child element 将CSS3动画悬停在其他元素上时开始? - CSS3 animation begin when hovering over a different element? 当 hover 在另一个子容器上时,使用 javascript 容器闪烁并同时删除和添加 CSS 类 - using javascript container blinking and remove and add CSS classes at same time when hover over another child container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM