1. Introduction
The emergence of CSS3 has made the performance of browsers more colorful. The one with the greatest impact is animation. When writing animations on a daily basis, it is necessary to determine in advance whether the browser supports it. , especially when writing CSS3 animation libraries. For example, transition animation-play-state is only supported by some browsers.
2. Detection method
The following method can use a script to determine whether the browser supports a certain CSS3 attribute:
Js code
- /**
- * Determine whether the browser supports a certain CSS3 attribute
- * @param {String} attribute name
- * @return {Boolean} true/false
- * @version 1.0
- * @author ydr.me
- * April 4, 2014 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));
- ] in htmlStyle) return true;
- return false;
- Js code
-
- alert(supportCss3('animation-play-state'));
-
-
4 , Reference materials- http://note.rpsh.net/posts/2011/05/20/css
http://ecd.tencent.com/css3/guide.html
-