How to stop an animation with zepto.js

Jump to: navigation, search

As of this writing, zeptojs has no support for jQuery's .stop(). If you can stomach some ugly code, you can work around this problem by nesting your animations. The example below animates opacity from 0 to 1 but can be programatically cancelled by setting isMyImageAnimationCancelled=true somewhere in your code. Granted the polling is not continuous, but if you keep the polling interval to under 0.5s the user will not notice. var isMyImageAnimationCancelled = false; $('#myImage').animate({'opacity':'0.25'}, 250, null, function() { if (isMyImageAnimationCancelled) { return;} $('#myImage').animate({'opacity':'0.5'}, 250, null, function() { if (isMyImageAnimationCancelled) { return;} $('#myImage').animate({'opacity':'0.75'}, 250, null, function() { if (isMyImageAnimationCancelled) {return;} $('#imgGClick').animate({'opacity':'1'}, 250); }); }); }); });

See also

Personal tools
Namespaces
Variants
Views
Actions
Navigation