CSS Rotating with jQuery
CSS transformations give a lot of new fancy and handy animations, but there could be some situations where you want javascript, maybe jQuery trigger them.
How to rotate something with jQuery then?
Here is the answer:
This is the function that extends jQuery:
$.fn.animateRotate = function(angle, duration, easing, complete) {
return this.each(function() {
var $elem = $(this);
$({deg: 0}).animate({deg: angle}, {
duration: duration,
easing: easing,
step: function(now) {
$elem.css({
transform: 'rotate(' + now + 'deg)'
});
},
complete: complete || $.noop
});
});
};
And you activate it simply by putting a:
$('#yourstuff').animateRotate(
0, // from angle
180, // to angle
1000, // duration
'linear', // easing
function(){
// and it's done!
}
);
Thanks to yckart
No comments yet.