Firefox Hover对SVG图像元件不起作用的效果
尝试制作交互式SVG地图。当将图像元素之一悬停在其上时,其大小应从20px增加到50px。这是我要做的事情的一个示例:
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" id="_x2014_1" x="0" y="0" version="1.1" viewBox="44.524925231933594 246.8045654296875 1111.1861572265625 608.7947998046875"><style>.st1{fill:#000000}</style>
<g clip-path="url(#SVGID_3_)">
<image x="207" y="408" href="https://picsum.photos/200/300" class="map_icon_small"></image>
<image x="227" y="500" href="https://picsum.photos/200/300" class="map_icon_small"></image>
<image x="395" y="658" href="https://picsum.photos/200/300" class="map_icon_small"></image>
<image x="345" y="705" href="https://picsum.photos/200/300" class="map_icon_small"></image>
</g>
</svg>
.map_icon_small{
width:20px;
transition: width 0.25s;
}
.map_icon_small:hover{
width:50px;
}
htttps://jsfiddle.net.net/x24dnjat/
这在Chrome/Edge/Safari中起作用,但是在Firefox中,鼠标悬停没有任何事情。我试图尝试使用其他建议,例如指针事件,将其更改为路径,以及许多其他建议。我不确定是否不支持它,或者是否还有另一种使元素在SVG上进行交互的方法。
Attempting to make an interactive SVG map. When one of the image elements is hovered over it should increase in size from 20px to 50px. Here is an example of what I'm trying to do:
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" id="_x2014_1" x="0" y="0" version="1.1" viewBox="44.524925231933594 246.8045654296875 1111.1861572265625 608.7947998046875"><style>.st1{fill:#000000}</style>
<g clip-path="url(#SVGID_3_)">
<image x="207" y="408" href="https://picsum.photos/200/300" class="map_icon_small"></image>
<image x="227" y="500" href="https://picsum.photos/200/300" class="map_icon_small"></image>
<image x="395" y="658" href="https://picsum.photos/200/300" class="map_icon_small"></image>
<image x="345" y="705" href="https://picsum.photos/200/300" class="map_icon_small"></image>
</g>
</svg>
.map_icon_small{
width:20px;
transition: width 0.25s;
}
.map_icon_small:hover{
width:50px;
}
https://jsfiddle.net/x24dnjat/
This works in chrome/edge/safari, but in firefox nothing happens on mouse hover. I've attempted to play around with other suggestions like pointer-events, changing the to a path, and numerous others to no avail. I'm not sure if it's just not supported or if there's another method of making an element interactive on an SVG.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从现有文件中拍摄并在Illustrator中编辑的SVG图像也有类似的问题。在原始内容中,
:悬停
类工作。在新文件上,:Hover
类在Chrome上工作,但在Firefox上不工作。事实证明,根据您在保存时选择的SVG格式,Illustrator在某些情况下会添加很多对CSS有害的东西。https://svgomg.net/ 解决了问题。
I had a similar problem with an SVG image that I had taken from an existing file and edited in Illustrator. In the original, the
:hover
class worked. On the new file, the:hover
class was working on Chrome, but not on Firefox. It turns out that depending on the SVG format you select when saving, Illustrator adds in lots of stuff that can be detrimental to CSS in some circumstances.A quick passage by https://svgomg.net/ solved the problem.
@ O17T H1H'S'K
如果您对触发该错误的确切情况感兴趣,则这里是HTML Page + SVG文件的组合,该文件在Chrome中起作用,但在Firefox中仍然惰性。
HTML页面:
SVG文件(可能是由Illustrator生成的):
@ o17t H1H' S'k
If you are interested in the exact circumstance that triggered the bug, here is a combination of html page + svg file that works in Chrome but remains inert in Firefox.
Html page:
Svg file (probably generated by Illustrator) :