【问题标题】:Jquery - How to prevent the loop, when we do click more than 3 times continuouslyJquery - 当我们连续点击超过 3 次时如何防止循环
【发布时间】:2015-01-02 20:54:47
【问题描述】:

这发生在响应式菜单中,我们执行连续点击多次,响应式打开菜单,这不会停止连续打开和关闭。

这里我举个简单的例子:

http://jsfiddle.net/milindex/uekp0rgr/2/

$(函数(){

    $('#boton').on('click', function(){ 
            event.preventDefault(); 
            $('.acction').toggle("slow");
    });

});

我看过很多替代方案和解决方案,但看起来很复杂,有一些更容易理解和实施?

【问题讨论】:

  • 你的小提琴给出错误event is not defined
  • @RocketR 仅在 Firefox 上

标签: jquery loops infinite-loop


【解决方案1】:

你应该停止动画:

$(function () {
    $('#boton').on('click', function (event) {
        event.preventDefault();
        $('.acction').stop().toggle("slow");
    });
});

-DEMO-

【讨论】:

  • A.沃尔夫非常感谢你,祝你有美好的一天,哦,新年快乐。
猜你喜欢
  • 2019-07-06
  • 2021-04-13
  • 2019-06-08
  • 2016-04-24
  • 1970-01-01
  • 2016-03-27
  • 1970-01-01
  • 2016-01-14
  • 1970-01-01
相关资源
最近更新 更多