javascript - 有时间间隔的点击事件
问题描述
$next.on(’click’,function(){ //清除定时器 clearInterval(t); //执行一次下一张轮播图的播放 setTimeout(next); //执行一次下一张轮播图的播放后执行轮播 setTimeout(t=window.setInterval( next, delay ),delay); });
如何给这个点击事件加上一个限制,要等5秒之后才能点击
问题解答
回答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))
相关文章:
1. docker容器呢SSH为什么连不通呢?2. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””3. docker网络端口映射,没有方便点的操作方法么?4. nignx - docker内nginx 80端口被占用5. debian - docker依赖的aufs-tools源码哪里可以找到啊?6. 前端 - ng-view不能加载进模板7. android clickablespan获取选中内容8. angular.js - angular内容过长展开收起效果9. python - from ..xxxx import xxxx到底是什么意思呢?10. angular.js - ng-grid 和tabset一起用时,grid width默认特别小
