【发布时间】:2015-10-06 13:00:50
【问题描述】:
我正在使用 SMIL 为 SVG 元素制作动画。我没有使用 CSS 动画,因为我没有为 CSS 属性设置动画,也没有使用 Web 动画,因为浏览器还不支持它们。
我想在动画结束时触发一个事件。有一个用于此的标准事件(“onend”),因此只需将其添加到元素即可。
在 Chrome 中,这似乎只有在我使用时才有效:
animation.onend = function(){thing();};
在 Firefox 中,这似乎只有在我使用时才有效:
animation.addEventListener("end", function(){thing();});
- 注意不同的事件名称,“onend”不起作用。
在 Safari 中,没有任何效果。以上两种方法我都试过了,还有
animation.setAttribute("onend", function(){thing();});
animation.setAttributeNS(null,"onend", function(){thing();});
animation.setAttributeNS("http://www.w3.org/2000/svg", function(){thing();});
animation.setAttribute("end", "thing();");
及其所有变体。检查器中的一切看起来都正确,但没有任何反应。
有什么线索可以让这个跨浏览器工作吗?
【问题讨论】:
标签: javascript html events svg