gpt4 book ai didi

html - 是否可以使用 CSS 在图像 map 上设置鼠标悬停样式?

转载 作者:行者123 更新时间:2023-11-28 00:05:40 25 4
gpt4 key购买 nike

我在网页上有一张图片也需要链接。我正在使用图像映射来创建链接,我想知道是否有一种方法可以在鼠标悬停时设置区域形状的样式以实现轻微的交互性。这可能吗?

我试过了没有成功:

html

<img src="{main_photo}" alt="locations map"  usemap="#location-map" />
<map name="location-map">
<area shape="rect" coords="208,230,290,245" href="{site_url}locations/grand_bay_al" />
<area shape="rect" coords="307,214,364,226" href="{site_url}locations/mobile_al" />
<area shape="rect" coords="317,276,375,290" href="{site_url}locations/loxley_al" />
</map>

CSS

area { border: 1px solid #d5d5d5; }

有什么建议吗?

最佳答案

仅 CSS:

在我去超市的路上想想,你当然也可以跳过整个图像映射的想法,并在图像顶部的元素上使用 :hover (改变了 div到 a block )。这让事情变得简单得多,不需要 jQuery...

简短说明:

  • 图片在底部
  • 2 x a with display:block and absolute positioning + opacity:0
  • 悬停时将不透明度设置为 0.2

示例:

.area {
background:#fff;
display:block;
height:475px;
opacity:0;
position:absolute;
width:320px;
}
#area2 {
left:320px;
}
#area1:hover, #area2:hover {
opacity:0.2;
}
<a id="area1" class="area" href="#"></a>
<a id="area2" class="area" href="#"></a>
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Saimiri_sciureus-1_Luc_Viatour.jpg/640px-Saimiri_sciureus-1_Luc_Viatour.jpg" width="640" height="475" />

使用 jQuery 的原始答案

我刚刚用 jQuery 创建了一些类似的东西,我认为它不能只用 CSS 来完成。

简短说明:

  • 图片在底部
  • 带翻转(图像或颜色)的 Div,带绝对定位 + display:none
  • 带有实际 #map 的透明 gif 位于顶部(绝对位置)(以防止在出现翻转时调用 mouseout)
  • jQuery 用于显示/隐藏 div

$(document).ready(function() {
if ($('#location-map')) {
$('#location-map area').each(function() {
var id = $(this).attr('id');
$(this).mouseover(function() {
$('#overlay' + id).show();

});

$(this).mouseout(function() {
var id = $(this).attr('id');
$('#overlay' + id).hide();
});

});
}
});
body,
html {
margin: 0;
}

#emptygif {
position: absolute;
z-index: 200;
}

#overlayr1 {
position: absolute;
background: #fff;
opacity: 0.2;
width: 300px;
height: 160px;
z-index: 100;
display: none;
}

#overlayr2 {
position: absolute;
background: #fff;
opacity: 0.2;
width: 300px;
height: 160px;
top: 160px;
z-index: 100;
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img src="http://www.tfo.be/jobs/axa/premiumplus/img/empty.gif" width="300" height="350" border="0" usemap="#location-map" id="emptygif" />
<div id="overlayr1">&nbsp;</div>
<div id="overlayr2">&nbsp;</div>
<img src="http://2.bp.blogspot.com/_nP6ESfPiKIw/SlOGugKqaoI/AAAAAAAAACs/6jnPl85TYDg/s1600-R/monkey300.jpg" width="300" height="350" border="0" />
<map name="location-map" id="location-map">
<area shape="rect" coords="0,0,300,160" href="#" id="r1" />
<area shape="rect" coords="0,161,300,350" href="#" id="r2"/>
</map>

希望对你有帮助..

关于html - 是否可以使用 CSS 在图像 map 上设置鼠标悬停样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55714911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com