Jquery - 使用toggle(),但在动画完成之前禁用它
我正在使用 jquery 切换函数,如下所示:
$(".class").toggle( 功能() { //要做的事情...动画等等 }, 功能(){ // 其他要做的事情... } );
现在,当我经常通过单击调用切换效果时,两个函数的动画不会等待另一个函数完成。所以我想禁用切换效果,直到每个函数中的内容完成。因此,当通过切换调用第一个函数时,第二个函数不应通过再次单击 .class 元素来调用。反过来
你知道我该怎么做吗?
提前致谢, 菲尔
i am using the jquery toggle function like this:
$(".class").toggle(
function() {
//things to do... animations and so on
},
function(){
// other things to do...
}
);
Now when I call the toggle effect by clicking very often the animations of the two functions don't wait for the other to finish. So I would like to disable the toggle effects undtil the stuff in each function is finished. So when the first function is called by the toggle the second one should not be called by another click on the .class element. And the other way round
Any idea how i could do that?
Thanks in advance,
Phil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在之前添加
.click()
处理程序绑定 执行此操作的切换开关,例如:它的作用是检查您的选择器和
:animated
发现任何元素(它们仍在动画),它会返回 false
并阻止.toggle()
处理程序甚至不会受到攻击。这是可行的,因为事件处理程序按照它们绑定的顺序执行,因此如果第一个返回false
,第二个将不会运行。You could add a
.click()
handler bound before the toggle that does this, for example:What this does is if the check for your selector and
:animated
found any elements (they're still animating), it'dreturn false
and prevent the.toggle()
handler from even getting hit. This works because event handlers are executed in the order they were bound, so if the first one returnsfalse
, the second won't run.