Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 want to detect with JavaScript or jQuery (it's indifferent if jQ or JS because I use/loaded already jQ on my site) if this rotation via CSS is supported?

I know Modernizr but just for that little thing I don't want to include that whole library (and speed down the website speed load).

like image 528
Poru Avatar asked Aug 27 '11 02:08

Poru


1 Answers

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;
}
like image 75
Roshambo Avatar answered Oct 20 '22 14:10

Roshambo