This can be done as follows:
$.fn.loopingAnimation = function(props, dur, eas) { if (this.data('loop') == true) { this.animate( props, dur, eas, function() { if( $(this).data('loop') == true ) $(this).loopingAnimation(props, dur, eas); }); } return this;
Now you can do this:
$("div.animate").hover(function(){ $(this).data('loop', true).stop().loopingAnimation({ left: "+10px"}, 300); }, function(){ $(this).data('loop', false);
If you want the animation to stop immediately, you can change the hoverOut line to read:
$(this).data('loop', false).stop();
Doug neiner
source share