判断浏览器是否支持某个CSS属性

版权声明:本文不管是不是原创,欢迎转载。 https://blog.csdn.net/alanfancy/article/details/50617631
if( attr in document.documentElement.style){
      return true;
}else{
      return false;
} 

如判断是否支持flex属性

<pre name="code" class="javascript">if( 'flex' in document.documentElement.style){
      return true;
}else{
      return false;
} 
 
 

 带横线的属性需要使用首字母小写的驼峰命名法,判断是否支持 text-shadow 
 

if( 'textShadow' in document.documentElement.style){
      return true;
}else{
      return false;
} 

带浏览器前缀的hack写法,则使用首字母大写开头,IE则使用小写的ms开头,判断是否支持 transform
<pre name="code" class="javascript">if( 'MozTransform' in document.documentElement.style || 
    'WebkitTransform' in document.documentElement.style || 
    'OTransform' in document.documentElement.style || 
    'msTransform' in document.documentElement.style){
	alert(1);
}else{
	alert(0);
}

 
  
 
 

猜你喜欢

转载自blog.csdn.net/alanfancy/article/details/50617631