Add Vendor Prefixes via Javascript

Fundamental 89 views
0
0 Flares 0 Flares ×
function getPrefixedVersion(property) {
var root = document.documentElement;
var prefixes = "webkit,Webkit,Moz,O,ms,Khtml".split(",");

if (property in root.style) {
return property;
}

property = property.charAt(0).toUpperCase() + property.slice(1);

for (var i = 0; i < prefixes.length; i++) {
if (prefixes[i] + property in root.style) {
return prefixes[i] + property;
}
}
}

Use this when applying CSS3 styles in JavaScript. For example to apply a rotation using the CSS3 transform property put:

element.style[getPrefixedVersion("transform")] = "rotate(90deg)"
Provided by: Jonathan Hodgson
Tagged with:
Posted in Javascript

Discuss:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

No Trackbacks.

Login

Register | Lost your password?
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×