js节流和防抖

节流:

  1. 

var throttle = function(fn,delay){
         var pre = Date.now();
          return function(){
                var __me = this;
                var args = arguments;
                var now = Date.now();
               if(now - pre >= delay){
                 fn.apply(__me,args);
                 pre = Date.now();
               }
         }
}
var count = 0;
window.onresize = throttle(function(){
         console.log(count++)
},1000)

 

posted @ 2019-08-03 15:57  江山一族  阅读(114)  评论(0编辑  收藏  举报