[英]How do I use Javascript to detect SVG Animation and Show/Hide Flash/SVG objects?
我一直在尝试使用SMIL创建SVG动画。 它在最新的Firefox中运行良好,但当然它在IE中不起作用。 我已经有了类似的Flash动画。 我的计划是在页面上包含Flash和SVG动画,并根据javascript检测显示/隐藏它们。 但我对javascript很恐怖,并且不知道该怎么做。 我将使用链接的.js文件。 我的计划是在页面加载时检测浏览器是否支持“http://www.w3.org/TR/SVG11/feature#AnimationEventsAttribute”功能,如果支持,则隐藏Flash对象(id =“rotateFlash “)并显示SVG对象(id =”rotateSVG“)。
我不知道是否有更好的方法来实现我想要的东西,而且我还没有找到任何类似于我想要实现的代码。 我发现了显示/隐藏javascripts,但不知道如何用它们来实现检测该功能。
这段代码似乎至少做了一些事情,但它似乎遵循“else”命令,我猜这意味着Firefox没有将该功能检测为“True”(IE9也不是,但这是预期的)。
function supportsSvg() {
if(document.implementation.hasFeature ("http://www.w3.org/TR/SVG11/feature#AnimationEventsAttribute", "1.0") == "true" ) {
document.getElementById("rotateSVG").style.display = "";
document.getElementById("rotateFlash").style.display = "none";
}
else {
document.getElementById("rotateSVG").style.display = "none";
document.getElementById("rotateFlash").style.display = "";
}
}
我不知道还能做什么。 我尝试过其他更简单的SVG功能,但我得到了相同的结果。 我一直在阅读有关Modernizr的内容,但对我来说这似乎太复杂了。 我不明白为什么,如果它会起作用。
我想我终于开始工作了。 查看代码后,我有一种感觉== "true"
是不必要的,所以我删除了它。 现在它似乎在Firefox 13和IE9中运行。
function supportsSvg() {
if(document.implementation.hasFeature ("http://www.w3.org/TR/SVG11/feature#AnimationEventsAttribute", "1.0")) {
document.getElementById("rotateSVG").style.display = "";
document.getElementById("rotateFlash").style.display = "none";
}
else {
document.getElementById("rotateSVG").style.display = "none";
document.getElementById("rotateFlash").style.display = "";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.