js节流

function _throttling(fn,wait,mustRun){
                var time=null;
                var startTime= new Date()
                return function(){
                    clearTimeout(time)
                    time=null;
                    var endTime=new Date();
                    if(endTime-startTime>=mustRun){
                        startTime=endTime;
                        fn();
                    }
                    else{
                        time=setTimeout(fn,wait)
                    }
                }
            }
_throttling(resetH,50,33)

 

posted @ 2018-09-06 16:05  dongxiaolei  阅读(162)  评论(0编辑  收藏  举报