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

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

如果对你有用,关注一下博主的小程序,登录一下给予支持,以后有什么开源好用的源码都会上传到小程序 

猜你喜欢

转载自blog.csdn.net/qq_42543264/article/details/121777020