这段SVG代码在多个浏览器(FF 8、Safari 5.1.2、Chrome 16,均在Mac上测试)中存在问题:当鼠标移动到矩形条上时,浏览器无法正确侦测到每个on-mouse-over/out事件,有时它有效,有时则无效。但所有的浏览器行为都一致,因此可能是SVG代码的问题。使用onmouseover
和onmouseout
会得到同样的结果 - 不工作。
在SVG rect
元素上实现悬停的正确方法是什么?
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="800" height="600" version="1.1" style="display:inline">
<style type="text/css">
.bar {
fill: none;
}
.bar:hover {
fill: red;
}
</style>
<g>
<rect class="bar" x="220" y="80" width="20" height="180" stroke="black" stroke-width="1" />
</g>
</svg>
.bar:hover
比.bar
更具体,因此样式仍然会接管。 - tomekwi