Home > Web Front-end > HTML Tutorial > JS determines whether the browser supports a certain CSS3 attribute_html/css_WEB-ITnose

JS determines whether the browser supports a certain CSS3 attribute_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:58:28
Original
1275 people have browsed it

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

  1. /**
  2. * Determine whether the browser supports a certain CSS3 attribute
  3. * @param {String} attribute name
  4. * @return {Boolean} true/false
  5. * @version 1.0
  6. * @author ydr.me
  7. * April 4, 2014 14:47:19
  8. */
  9. function supportCss3(style) {
  10. var prefix = ['webkit', 'Moz', 'ms', 'o'],
  11. i,
  12. humpString = [],
  13. htmlStyle = document.documentElement.style,
  14. _toHumb = function (string) {
  15. return string.replace(/-(w)/g, function ($0, $1) {
  16. return $1.toUpperCase();
  17. });
  18. };
  19. for (i in prefix) humpString.push(_toHumb(prefix[i] '-' style));
  20.  
  21. humpString.push(_toHumb(style));
  22.                                     ] in htmlStyle) return true;
  23. return false;
  24. Js code
  25. alert(supportCss3('animation-play-state'));
  26. 4 , Reference materials
  27. http://note.rpsh.net/posts/2011/05/20/css
http://ecd.tencent.com/css3/guide.html

Related labels:
source:php.cn
Previous article:After the HTML page is loaded, adjust the height of the