I have the following jQuery extension:
(function ($) { //jQuery plugin extension
jQuery.fn.rotate = function(degree, maxDegree) {
this.css({ WebkitTransform: 'rotate(' + degree + 'deg)'});
this.css({ '-moz-transform': 'rotate(' + degree + 'deg)'});
// Animate rotation with a recursive call
rotation = setInterval(function() {
if (degree < (maxDegree/2)) {
$(this).rotate(++degree);
} else {
clearInterval(rotation);
}
},5);
};
}(jQuery));
And I’m calling it like this:
$('#test').live('mouseover',function() {
$(this).rotate(0, 360);
});
But it doesn’t fire, here is a JSFiddle:
http://jsfiddle.net/neuroflux/8vZqr/
( Note, the fiddle won’t run because of the live() )
You are not calling the function you have your plugin in:
Furthermore,
thisinside thesetIntervalmethod does not refer to the selected elements anymore, but towindow. You have to keep a reference tothis:I would als make
rotationa local variable (withvar) otherwise you will get in trouble if the function fires on several elements.As for your fiddle, you did not select jQuery to use as library.
If this is all fixed, it works → .