jQuery stop(true,true)跳转到队列中所有动画的结尾 [英] jQuery stop(true, true) to jump to end of all animations in queue

查看:126
本文介绍了jQuery stop(true,true)跳转到队列中所有动画的结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用jQuery的stop(true, true)方法清除正在运行的动画,因此下一个动画立即开始.我注意到第一个参数clearQueue清除了整个动画队列,但是第二个参数jumpToEnd仅跳转到当前正在运行的动画的末尾,而不是从队列中删除的动画.有没有办法清除它并跳到所有排队动画的结尾?

I have been using jQuery's stop(true, true) method to clear running animations so the next one starts immediately. I noticed that the first parameter, clearQueue, clears the entire animation queue but the second parameter, jumpToEnd, only jumps to the end of the currently running animation and not the ones that were removed from the queue. Is there a way to have it clear and jump to the end of all queued animations?

我最终链接了几个stop(false, true)调用,但是,例如,这只能处理3个排队的动画.

I've ended up chaining a few stop(false, true) calls instead, but this will only handle 3 queued animations, for example.

$(this)
  .stop(false, true)
  .stop(false, true)
  .stop(false, true)
  .addClass('hover', 200);

根据Ates Goral的回答,我最终添加了自己的方法stopAll:

I ended up adding my own method, stopAll, as per Ates Goral's answer:

$.fn.extend({ stopAll: function () {
    while (this.queue().length > 0)
      this.stop(false, true);
    return this;
  } });

$(this).stopAll().addClass('hover', 200);

我希望其他人觉得这有用.

I hope someone else finds this useful.

推荐答案

jQuery 1.9引入了 .finish()方法,即可实现这一目标.

jQuery 1.9 introduced the .finish() method, which achieves exactly that.

这篇关于jQuery stop(true,true)跳转到队列中所有动画的结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆