How to set the style -webkit-transform dynamically using JavaScript?

rymn picture rymn · Apr 2, 2009 · Viewed 206.5k times · Source

I want to change the -webkit-transform: rotate() property using JavaScript dynamically, but the commonly used setAttribute is not working:

img.setAttribute('-webkit-transform', 'rotate(60deg)');

The .style is not working either...

How can I set this dynamically in JavaScript?

Answer

Ólafur Waage picture Ólafur Waage · Apr 2, 2009

The JavaScript style names are WebkitTransformOrigin and WebkitTransform

element.style.webkitTransform = "rotate(-2deg)";

Check the DOM extension reference for WebKit here.