[jQuery] Stop animation work-around
I've written a small plug-in work-around for stopping animation - not very pretty, but does the job while waiting for the 'official' version in jQuery 1.2.
I Would like some feedback (not too harsh please!).
The plug-in was inspired by the original 'easing' plug-in by George Smith and goes like this:
<font size="1"><span style="font-family: courier new,monospace;">// Modify fx function by converting first to a String
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">jQuery.fx = String(jQuery.fx).replace(RegExp("13\\);"), "13);if (options.handle){ eval('window.'+options.handle+'=
z.timer');}");</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
// make it a Function again</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">jQuery.fx = Function( "elem", "options", "prop", jQuery.fx.substring
(jQuery.fx.indexOf('{')+1, jQuery.fx.lastIndexOf('}')));</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">// Clear the Queue</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$.fn.clearQueue = function(type) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return this.each(function(){</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> type = type || "fx";
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if(this.queue && this.queue[type]) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
this.queue[type].length = 0;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
});</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">};</span></font>
Then to use it you do something like this:
<font size="1"><span style="font-family: courier new,monospace;">
<script type="text/javascript"></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">window.aHandle=null;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">function startAnimate() {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
$('#abc').animate({left:500}, { complete:function(){},</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> duration:5000,</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> easing:true,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
handle:'aHandle'}, 'easein');</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">function stopAnimate() {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> window.clearInterval(window.aHandle);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $('#abc').clearQueue();
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"></script>
</span><br style="font-family: courier new,monospace;"></font>
Lincoln.
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/