Here is a simple jQuery example, check out the modified JSFiddle:
http://jsfiddle.net/g3k6h/5/
CSS will handle rotations> 360 and <0 for me, so I didn’t even bother to do this and adjust the rotation value based on scrolling by distance. I was not worried about trying to explain the full turn so that it would flow better with scrolling speed and distance. This solution depends on jQuery, but can easily be done without it.
$(function() { var rotation = 0, scrollLoc = $(document).scrollTop(); $(window).scroll(function() { var newLoc = $(document).scrollTop(); var diff = scrollLoc - newLoc; rotation += diff, scrollLoc = newLoc; var rotationStr = "rotate(" + rotation + "deg)"; $(".gear").css({ "-webkit-transform": rotationStr, "-moz-transform": rotationStr, "transform": rotationStr }); }); })
source share