如何防止 JQuery 排队(链接)
场景:您可以单击一个按钮,一些内容将向左移动(.animate)。 当您快速单击按钮约 3 次时,JQuery ques 3 .animate 将按顺序排列。
我不想那样!我将阻止这种排队,因此该按钮仅在动画完成时才起作用。 谢谢你的每一个云!
伪代码:
IF #Content 不是动画(静止不动)
THEN On Click Button
Animate Contet CSS "left" + 900px
ELSE 您现在无法单击该按钮。但是如果你点击按钮,那么它就不会出现另一个动画。
Scenario: You can click a Button and some Content will move (.animate) left.
When you click the button fast for about 3 times then JQuery ques 3 .animate left's in the order.
I dont want that! I will prevent that queing so the button will only work when the animation is done.
Thank you for every clou!
Pseudo Code:
IF #Content is NOT animated (stands still)
THEN On Click Button
Animate Contet CSS "left" + 900px
ELSE You can't click the button now. But ff you click the butto,n then it wont que another animation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
:animated
选择器 来运行基于元素的动画状态。这也使用
:not()
选择器,以及.is()
方法 返回布尔值。或者,您可以在动画开始时向按钮添加一个类,并使用该类作为标志来确定动画是否应该运行。
该类还可以设置按钮的样式,以提供不应再次单击该按钮的反馈。
You can use the
:animated
selector to run code based on the animated state of an element.This also uses the
:not()
selector, and the.is()
method to return a boolean.Or you could add a class to the button when the animation starts, and use that class as a flag to determine if the animation should run.
The class could also style the button to give feedback that it shouldn't be clicked again.
您始终可以在按下时取消绑定
click
事件。然后将回调传递给animate,一旦动画播放,它将重新绑定click
已完成。You could always unbind the
click
event when it is pressed. Then pass a callback to animate that will re-bindclick
once the animation is complete.