Detect with JavaScript or jQuery if CSS transform 2D is available

前端 未结 5 1157
攒了一身酷
攒了一身酷 2021-02-04 09:01

I\'m displaying a element on my site which I rotate with -90deg but if a browser doesn\'t support the CSS transform the element looks misspositioned and not really good. Now I w

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-04 09:20

    This is about as simple as you get and a jsfiddle. It no longer goes on an infinite loop.

    function getSupportedTransform() {
        var prefixes = 'transform WebkitTransform MozTransform OTransform msTransform'.split(' ');
        for(var i = 0; i < prefixes.length; i++) {
            if(document.createElement('div').style[prefixes[i]] !== undefined) {
                return prefixes[i];
            }
        }
        return false;
    }
    

提交回复
热议问题