JS判断浏览器是否支持某一个CSS3属性的方法
2016-04-05 17:47
1086 查看
1、引子
css3的出现让浏览器的表现更加的丰富多彩,表现冲击最大的就是动画了,在日常书写动画的时候,很有必要去事先判断浏览器是否支持,尤其是在写CSS3动画库的时候。比如transition的animation-play-state,就只有部分浏览器支持。
2、检测方法
下面的方法可以使用脚本判断浏览器是否支持某一个CSS3属性:
?
function supportCss3(style) {
var prefix = ['webkit', 'Moz', 'ms', 'o'],
i,
humpString = [],
htmlStyle = document.documentElement.style,
_toHumb = function (string) {
return string.replace(/-(\w)/g, function ($0, $1) {
return $1.toUpperCase();
});
};
for (i in prefix)
humpString.push(_toHumb(prefix[i] + '-' + style));
humpString.push(_toHumb(style));
for (i in humpString)
if (humpString[i] in htmlStyle) return true;
return false;
}
if(supportCss3('animation-play-state')){
top.window.location.href="forwardloginAction";
}else{
alert("请更换你的浏览器进行访问");
}
3、使用方法
if(supportCss3('animation-play-state')){
top.window.location.href="forwardloginAction";
}else{
alert("请更换你的浏览器进行访问");
}
alert(supportCss3('animation-play-state'));
原址:http://www.jb51.net/article/56412.htm
css3的出现让浏览器的表现更加的丰富多彩,表现冲击最大的就是动画了,在日常书写动画的时候,很有必要去事先判断浏览器是否支持,尤其是在写CSS3动画库的时候。比如transition的animation-play-state,就只有部分浏览器支持。
2、检测方法
下面的方法可以使用脚本判断浏览器是否支持某一个CSS3属性:
?
function supportCss3(style) {
var prefix = ['webkit', 'Moz', 'ms', 'o'],
i,
humpString = [],
htmlStyle = document.documentElement.style,
_toHumb = function (string) {
return string.replace(/-(\w)/g, function ($0, $1) {
return $1.toUpperCase();
});
};
for (i in prefix)
humpString.push(_toHumb(prefix[i] + '-' + style));
humpString.push(_toHumb(style));
for (i in humpString)
if (humpString[i] in htmlStyle) return true;
return false;
}
if(supportCss3('animation-play-state')){
top.window.location.href="forwardloginAction";
}else{
alert("请更换你的浏览器进行访问");
}
3、使用方法
if(supportCss3('animation-play-state')){
top.window.location.href="forwardloginAction";
}else{
alert("请更换你的浏览器进行访问");
}
alert(supportCss3('animation-play-state'));
原址:http://www.jb51.net/article/56412.htm
相关文章推荐
- CSS布局奇淫技巧之--各种居中
- 妙味课堂——HTML+CSS(第四课)(二)
- setStyleSheet来设定窗口部件的样式
- css:box-sizing总结
- HTML+CSS画同心圆
- 高健壮性css---Float详细
- CSS学习笔记(二)选择器
- 【前端】使用CSS使元素居中的几种方式
- CSS设置元素水平居中、垂直居中方式汇总
- CSS定位规则之BFC 你居然一直不知道的东西!!!!!
- 底部线条css样式
- css实现圆,半圆,四分之一圆和其他几何图形画法
- CSS元素的width和水平margin的设置
- 妙味课堂——HTML+CSS(第四课)(一)
- CSS3 background-size 属性值:cover
- CSS样式大全
- 有用好看的CSS+JS+table 导航
- CSS学习笔记(一)
- CSS
- css3 transition 实例及分析 图片hover出现文字 sidebar平滑过渡(动画系列3)