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).
This is about as simple as you get and a jsfiddle. It no longer goes on an infinite loop.
Just pull what you need out of Modernizr
First we need the testProps function
Then run the cssTransform test
if tests['csstransforms'] is true, then you have the feature available.
Here's the code I'm using to detect if CSS3 transitions are supported:
I'm purposefully not looking for Microsoft support since Microsoft hasn't yet shipped a browser that supports CSS3 transitions and I don't want my code automatically supporting an implementation I haven't tested yet in the future.
This code tests for 2D transforms support.
It can be easily adjusted to detect 3D transforms support instead. Just add 'translateZ(1)' to test CSS (see
defaultTestValues
in source code).The plus of this code is that it detects the vendor prefix supported (if any). Call it:
Possible return values:
false
, when feature unsupported, orwhen feature supported
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.