Use CSS3 transform
, transition
and Javascript to add / remove classes.
Demo: http://jsfiddle.net/ThinkingStiff/AEeWm/
HTML:
<div id="rotate">hover me</div>
CSS:
#rotate { border: 1px solid black; height: 100px; width: 100px; } .over { transform: rotate( -180deg ); transition: transform 150ms ease; } .out { transform: rotate( -360deg ); transition: transform 150ms ease; }
Script:
var rotate = document.getElementById( 'rotate' ); rotate.addEventListener( 'mouseover', function () { this.className = 'over'; }, false ); rotate.addEventListener( 'mouseout', function () { var rotate = this; rotate.className = 'out'; window.setTimeout( function () { rotate.className = '' }, 150 ); }, false );
source share