Skip to content

Instantly share code, notes, and snippets.

@Bellfalasch
Created February 9, 2015 09:49
Show Gist options
  • Save Bellfalasch/f8c730ac6a38d7b2ecef to your computer and use it in GitHub Desktop.
Save Bellfalasch/f8c730ac6a38d7b2ecef to your computer and use it in GitHub Desktop.
Rotate an image on click (nice "load" animation)
// Rotate image
// http://stackoverflow.com/questions/15191058/css-rotation-cross-browser-with-jquery-animate
// Call: $('#loadmore span').animateRotate( 360, 500, 'swing', null );
$.fn.animateRotate = function(angle, duration, easing, complete) {
var args = $.speed(duration, easing, complete);
var step = args.step;
return this.each(function(i, e) {
args.step = function(now) {
$.style(e, 'transform', 'rotate(' + now + 'deg)');
if (step) return step.apply(this, arguments);
};
$({deg: 0}).animate({deg: angle}, args);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment