js window resize延时

 1 /*
 2          * 绑定element resize事件
 3          * =====================*/
 4         resize: function(element, callback){
 5             var delay = 500;        //window resize事件延时500毫秒
 6             var controlTime = 0;
 7             $(window, element).resize(function(){
 8                 var nowTime = new Date().getTime();
 9                 if(controlTime){
10                     setTimeout(function(){
11                         if(nowTime - controlTime > delay){
12                             if(typeof callback == 'function'){
13                                 controlTime = callback();
14                             }
15                         }
16                     }, delay);
17                 }else{
18                     setTimeout(function(){
19                         if(typeof callback == 'function'){
20                             controlTime = callback();
21                         }
22                     }, delay);
23                     controlTime ++;
24                 }
25             })
26         }

 

posted @ 2016-04-26 18:14  下一个雨季~  阅读(687)  评论(0编辑  收藏  举报