// 防止快速连续点击,节流函数
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