CSS Transitions Rotating img
Solution 1:
The transform:rotate()
CSS property has to be used. I've written a (simple?) pure JS function for this purpose.
JS:
function rotate(elem, angle){
//Cross-browser:
var css = ["-moz-","-webkit-","-ms-","-o-","",""]
.join("transform:rotate(" + angle + "deg);")
elem.style.cssText += css;
}
Example, Fiddle: http://jsfiddle.net/zvuyc/:
<script>
window.onload = function(){
var angle = 0;
document.getElementById("button").onclick = function(){
angle += 90 % 360;
rotate(document.getElementById("image"), angle);
}
}
</script>
<input type="button" id="button" value="Rotate by 90deg">
<img src="http://simplyeng.com/wp-content/uploads/2008/11/indiana_tux.png" id="image" />