【发布时间】:2014-12-21 18:51:42
【问题描述】:
我正在尝试使用 SVG <set> 标记为翻转设置动画,但即使我指定了 dur="1s",过渡也是瞬时的(在 Firefox、Safari、Opera 和 Chrome 中)。
<html>
<body>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red">
<set attributeType="CSS" attributeName="fill" to="green" begin="mouseover" end="mouseout" dur="1s" />
</circle>
</svg>
</body>
</html>
我可以使用两个<animate> 标签来实现我想要的效果,但是我希望能够将过渡应用到我想要保留的可能具有不同初始颜色的多个元素(此方法要求我指定初始颜色)第二个动画标签中的颜色为“红色”)。
<html>
<body>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red">
<animate attributeType="CSS" attributeName="fill" to="green" begin="mouseover" dur="1s" fill="freeze" />
<animate attributeType="CSS" attributeName="fill" to="red" begin="mouseout" dur="1s" fill="freeze"/>
</circle>
</svg>
</body>
</html>
第一个代码段中的<set> 标记保留了初始颜色,但过渡没有动画效果。如果我对 w3 规范的理解是正确的,那应该是 - 这看起来像是特定于浏览器的错误,还是我误解了 w3 规范?有没有更好的方法来解决这个问题?
【问题讨论】:
-
复制案例:jsfiddle.net/4xx5p(在 Safari 和 Firefox 上都是如此)
-
感谢您确认它在 Safari 中也不起作用;我也刚刚在 Opera 和 Chrome 中进行了测试,我也得到了相同的行为。