函数节流,待解决。

function throttle(method,delay,duration){
            var timer=null, begin=new Date();
            return function(){
                var context=this, args=arguments, current=new Date();;
                clearTimeout(timer);
                if(current-begin>=duration){
                     method.apply(context,args);
                     begin=current;
                }else{
                    timer=setTimeout(function(){
                        method.apply(context,args);
                    },delay);
                }
            }
}

window.onresize=throttle(resizehandler,100,200);

 

 n=0;
        function resizehandler(){
            console.log(new Date().getTime());
            console.log(++n);
        }
posted @ 2016-12-27 15:55  土豆zhang  阅读(141)  评论(0编辑  收藏  举报