aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2007-09-04 00:28:22 +0000
committerJohn Resig <jeresig@gmail.com>2007-09-04 00:28:22 +0000
commit1ce8006d480ebd64350983a17be1cc2e3f043958 (patch)
tree026a755acb03ef2caadedc68850b005b362a2c4d /src
parentd5bb0e317988965306b1ccb395fafc4554aba49c (diff)
downloadjquery-1ce8006d480ebd64350983a17be1cc2e3f043958.tar.gz
jquery-1ce8006d480ebd64350983a17be1cc2e3f043958.zip
Added a new .stop() method which stops all animations running on the matched set of elements.
Example: $("#foo").slideDown(1000); setTimeout(function(){ $("#foo").stop(); }, 500);
Diffstat (limited to 'src')
-rw-r--r--src/fx/fx.js18
-rw-r--r--src/fx/fxTest.js23
2 files changed, 39 insertions, 2 deletions
diff --git a/src/fx/fx.js b/src/fx/fx.js
index 075d1abb4..69885e890 100644
--- a/src/fx/fx.js
+++ b/src/fx/fx.js
@@ -368,6 +368,16 @@ jQuery.fn.extend({
if ( this.queue[type].length == 1 )
fn.apply(this);
});
+ },
+
+ stop: function(){
+ var timers = jQuery.timers;
+
+ return this.each(function(){
+ for ( var i = 0; i < timers.length; i++ )
+ if ( timers[i].elem == this )
+ timers.splice(i--, 1);
+ });
}
});
@@ -466,9 +476,13 @@ jQuery.extend({
z.now = from;
z.a();
- jQuery.timers.push(function(){
+ function t(){
return z.step(from, to);
- });
+ }
+
+ t.elem = elem;
+
+ jQuery.timers.push(t);
if ( jQuery.timers.length == 1 ) {
var timer = setInterval(function(){
diff --git a/src/fx/fxTest.js b/src/fx/fxTest.js
index 3c0d57db6..1f9e674a1 100644
--- a/src/fx/fxTest.js
+++ b/src/fx/fxTest.js
@@ -11,6 +11,29 @@ test("animate(Hash, Object, Function)", function() {
});
});
+test("stop()", function() {
+ expect(3);
+ stop();
+ reset();
+
+ var foo = $("#foo")[0];
+ var h = foo.style.height;
+
+ $("#foo").slideUp(1000);
+ setTimeout(function(){
+ var nh = foo.style.height;
+ ok( nh != h, "An animation occurred " + nh + " " + h );
+ $("#foo").stop();
+
+ nh = foo.style.height;
+ ok( nh != h, "Stop didn't reset the animation " + nh + " " + h );
+ setTimeout(function(){
+ equals( nh, foo.style.height, "The animation didn't continue" );
+ start();
+ }, 100);
+ }, 100);
+});
+
test("toggle()", function() {
expect(3);
var x = $("#foo");