search

Home  >  Q&A  >  body text

javascript - click event with time interval

$next.on('click',function(){
            //清除定时器
            clearInterval(t);
            //执行一次下一张轮播图的播放
            setTimeout(next);
            //执行一次下一张轮播图的播放后执行轮播
            setTimeout(t=window.setInterval( next, delay ),delay);
    });

How to add a limit to this click event, and you have to wait 5 seconds before clicking

仅有的幸福仅有的幸福2709 days ago693

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-06-26 11:00:07

    var overtime = true;
       $next.on("click",function(){
            if(!overtime){
                return;
            }
            console.log("click success");
            overtime = false;
        });
        var catchTimer = setInterval(function(){
            overtime = true;
        },5000);

    reply
    0
  • 滿天的星座

    滿天的星座2017-06-26 11:00:07

    function throttle (func, duration) {
        let start
        return function () {
            if (!start) start = Date.now()
            else if (start + duration > Date.now()) return
            
            func.apply(this, arguments)
        }
    }
    
    $next.on('click', throttle(function () {
        // Your code
    }, 5000))

    reply
    0
  • Cancelreply