函数节流防抖

// 节流函数
function throttle(fn, delay){
var t = null,
begin = new Date().getTime();

return function(){
  var _self = this,
      args = arguments,
      cur = new Date().getTime();

  clearTimeout(t);

  if(cur - begin >= delay){
    fn.apply(_self, args);
    begin = cur;
  }else{
    t = setTimeout(function(){
      fn.apply(_self, args);
    }, delay);
  }
}

}

posted @ 2020-06-29 20:59  古月大叔  阅读(111)  评论(0编辑  收藏  举报