Home > Web Front-end > JS Tutorial > JS method to determine whether the browser supports a certain CSS3 attribute_javascript skills

JS method to determine whether the browser supports a certain CSS3 attribute_javascript skills

WBOY
Release: 2016-05-16 16:33:23
Original
1525 people have browsed it

1、引子

css3的出现让浏览器的表现更加的丰富多彩,表现冲击最大的就是动画了,在日常书写动画的时候,很有必要去事先判断浏览器是否支持,尤其是在写CSS3动画库的时候。比如transition的animation-play-state,就只有部分浏览器支持。

2、检测方法

下面的方法可以使用脚本判断浏览器是否支持某一个CSS3属性:

/** 
* 判断浏览器是否支持某一个CSS3属性 
* @param {String} 属性名称 
* @return {Boolean} true/false 
* @version 1.0 
* @author ydr.me 
* 2014年4月4日14:47:19 
*/ 

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; 
}
Copy after login

3、使用方法

alert(supportCss3('animation-play-state'));

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template