1

我有一个绑定到 .click() 事件的函数。每次用户点击时,浏览器fadeOut() 当前元素和animate() 新元素的marginLeft。出于某种原因,当我快速单击绑定到此单击事件的按钮时,在 Chrome 中它会跳转动画并直接继续下一个(仅当我在 1 秒内单击 5 次时)并且不添加marginLeft,在这种情况下,它会导致 UI 的主要可用性问题。这种情况有没有后备方案?就像动画没有完成直接用 css() 或类似的东西添加它?

谢谢

E:click() 事件调用一个函数,所有的魔法都会在其中发生,如果它有帮助的话..

4

1 回答 1

2

您可能想查看 jquery 的.stop()方法。它允许您短路元素上任何当前正在运行的动画。

简单的例子:

$myElement.on('click', function() {
    // first 'true' clears animations in the queue for this element
    // second 'true' completes the currently-running animation immediately
    $(this).stop(true, true).fadeOut();
});

http://api.jquery.com/stop/

于 2013-04-16T23:54:48.417 回答