Check browser CSS property support with JavaScript?

眉间皱痕 提交于 2019-11-26 19:56:50

I believe you can do it this way:

if ('WebkitTransform' in document.body.style 
 || 'MozTransform' in document.body.style 
 || 'OTransform' in document.body.style 
 || 'transform' in document.body.style) 
{
    alert('I can Rotate!');
}
termi

There is a new DOM API CSS.supports for that purpose. FF, Opera (as supportsCSS) and Chrome Canary already implement this method.

For cross-browser compatibility you can use my CSS.supports polyfill

Example:

CSS.supports("display", "table");//IE<8 return false

But, you still need to specify browser prefix for prefixing css properties. For example:

CSS.supports("-webkit-filter", "blur(10px)");

I suggest to using Modernizr for feature-detection.

You can use Modernizr library.

Example for css transform:

in .css file;

.no-csstransforms .box { color: red; }
.csstransforms .box { color: green; }

in .js file;

if (Modernizr.csstransforms) {
  // supported
} else {
  // not-supported
}

May be try this?

var temp = document.createElement('div');
var isSupport = temp.style['propName'] != undefined;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!