javascript - 有時間間隔的點(diǎn)擊事件
問題描述
$next.on(’click’,function(){ //清除定時器 clearInterval(t); //執(zhí)行一次下一張輪播圖的播放 setTimeout(next); //執(zhí)行一次下一張輪播圖的播放后執(zhí)行輪播 setTimeout(t=window.setInterval( next, delay ),delay); });
如何給這個點(diǎn)擊事件加上一個限制,要等5秒之后才能點(diǎn)擊
問題解答
回答1:var overtime = true; $next.on('click',function(){if(!overtime){ return;}console.log('click success');overtime = false; }); var catchTimer = setInterval(function(){overtime = true; },5000);回答2:
function throttle (func, duration) { let start return function () {if (!start) start = Date.now()else if (start + duration > Date.now()) returnfunc.apply(this, arguments) }}$next.on(’click’, throttle(function () { // Your code}, 5000))
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. win10系統(tǒng) php安裝swoole擴(kuò)展3. extra沒有加載出來4. mysql - php 如何網(wǎng)址中出現(xiàn)該頁標(biāo)題?5. Span標(biāo)簽6. 關(guān)于Mysql數(shù)據(jù)表行轉(zhuǎn)列7. django進(jìn)行數(shù)據(jù)庫的查詢8. PHP求助,求幫忙謝謝各位9. javascript - 釘釘?shù)膃xcel, word文件預(yù)覽是直接用的微軟的office web app,不犯法嗎?10. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時間會消失是什么情況?
