Hosting Solutions
mobile_logo Table of Contents

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")){ = "rotate("+degrees+"deg)"; } else if(navigator.userAgent.match("Firefox")){ = "rotate("+degrees+"deg)"; } else if(navigator.userAgent.match("MSIE")){ = "rotate("+degrees+"deg)"; } else if(navigator.userAgent.match("Opera")){ = "rotate("+degrees+"deg)"; } else { = "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>

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