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

前端 未结 5 1158
攒了一身酷
攒了一身酷 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条回答
  •  -上瘾入骨i
    2021-02-04 09:28

    Here's a function based on Liam's answer. It will return either the name of the first supported prefix or false if none of the prefixes are supported.

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

提交回复
热议问题