JS判斷瀏覽器是否支援某一個CSS3屬性

來源:互聯網
上載者:User

標籤:style   http   color   io   os   ar   使用   java   for   

1、引子

css3的出現讓瀏覽器的表現更加的豐富多彩,表現衝擊最大的就是動畫了,在日常書寫動畫的時候,很有必要去事先判斷瀏覽器是否支援,尤其是在寫CSS3動畫庫的時候。比如transition的animation-play-state,就只有部分瀏覽器支援。

2、檢測方法

下面的方法可以使用指令碼判斷瀏覽器是否支援某一個CSS3屬性:

Js代碼  
  1. /** 
  2.     * 判斷瀏覽器是否支援某一個CSS3屬性 
  3.     * @param {String} 屬性名稱 
  4.     * @return {Boolean} true/false 
  5.     * @version 1.0 
  6.     * @author ydr.me 
  7.     * 2014年4月4日14:47:19 
  8. */  
  9.        
  10. function supportCss3(style) {  
  11.     var prefix = [‘webkit‘, ‘Moz‘, ‘ms‘, ‘o‘],  
  12.     i,  
  13.     humpString = [],  
  14.     htmlStyle = document.documentElement.style,  
  15.     _toHumb = function (string) {  
  16.     return string.replace(/-(\w)/g, function ($0, $1) {  
  17.     return $1.toUpperCase();  
  18.     });  
  19.     };  
  20.        
  21.     for (i in prefix)  
  22.     humpString.push(_toHumb(prefix[i] + ‘-‘ + style));  
  23.        
  24.     humpString.push(_toHumb(style));  
  25.        
  26.     for (i in humpString)  
  27.     if (humpString[i] in htmlStyle) return true;  
  28.        
  29.     return false;  
  30. }  

 

3、使用方法Js代碼  
  1. alert(supportCss3(‘animation-play-state‘));  

 

4、參考資料

http://note.rpsh.net/posts/2011/05/20/css

http://ecd.tencent.com/css3/guide.html

JS判斷瀏覽器是否支援某一個CSS3屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.