Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

Transform Rotate Image Spin Smooth Animation Tutorial

Learn to program any CSS property animations you want using JavaScript and the CSS3 transform property, and just a few lines of code. JavaScript offers your animations more flexibility regarding user interactivity with your animations. CSS alone cannot offer you all of the DOM event handlers that are useful for programming advanced interactivity with the animated elements. <!DOCTYPE html> <html> <head> <script> var looper; var degrees = 0; function rotateAnimation(el,speed){ var elem = document.getElementById(el); if(navigator.userAgent.match("Chrome")){ elem.style.WebkitTransform = "rotate("+degrees+"deg)"; } else if(navigator.userAgent.match("Firefox")){ elem.style.MozTransform = "rotate("+degrees+"deg)"; } else if(navigator.userAgent.match("MSIE")){ elem.style.msTransform = "rotate("+degrees+"deg)"; } else if(navigator.userAgent.match("Opera")){ elem.style.OTransform = "rotate("+degrees+"deg)"; } else { elem.style.transform = "rotate("+degrees+"deg)"; } looper = setTimeout('rotateAnimation(\''+el+'\','+speed+')',speed); degrees++; if(degrees > 359){ degrees = 1; } document.getElementById("status").innerHTML = "rotate("+degrees+"deg)"; } </script> </head> <body> <img id="img1" src="cog1.png" alt="cog1"> <script>rotateAnimation("img1",30);</script> <h2 style="width:200px;" id="status"></h2> </body> </html>
thumb

JavaScript Videos

Animation Programming

Trigger CSS Transitions to Control AnimationsStart Stop CSS keyframes animation with JavaScriptMenu Button Marker Animation TutorialTransform Rotate Image Spin Smooth Animation TutorialBubbles Content Slideshow Application JavaScript CSS HTML