使用JavaScript检测对转换的支持 [英] Detect support for transition with JavaScript
问题描述
我想根据浏览器是否支持CSS3转换来投放不同的JavaScript文件。是否有更好的方法来检测转移支持比我的代码下面?
I want to serve different javascript files depending on if browser supports CSS3 transition or not. Is there a better way to detect transition support than my code below?
window.onload = function () {
var b = document.body.style;
if(b.MozTransition=='' || b.WebkitTransition=='' || b.OTransition=='' || b.transition=='') {
alert('supported');
} else {
alert('NOT supported')
}
}
推荐答案
Modernizr会为您检测这个问题。使用此链接创建仅包含CSS3 2D和/或3D过渡的自定义下载内容。
Modernizr will detect this for you. Use this link to create a custom download build that only contains CSS3 2D and/or 3D transitions.
运行后,您可以在 html $ c $上测试
csstransitions
c> tag(CSS)或在JavaScript中,测试 Modernizr.csstransitions
是 true
。
Once it's run, you can either test for the csstransitions
class on the html
tag (CSS), or in JavaScript, test if Modernizr.csstransitions
is true
.
更多文档: http://modernizr.com/docs/#csstransitions
这篇关于使用JavaScript检测对转换的支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!