0
点赞
收藏
分享

微信扫一扫

前端防止快速连续点击,节流函数


// 防止快速连续点击,节流函数
function throttle(fun, delay) {
let oadDate = Date.now();
return function() {
let _this = this;
let args = arguments;
let newDate = Date.now();
if(newDate-oadDate > delay) {
fun.apply(_this, args);
oadDate = Date.now();
}
}
}

调用方法:click:throttle(function {// 点击操作}, 1000), 1000设置时间 1s

 

举报

相关推荐

0 条评论