首页 > 其他 > 详细

节流 防抖

时间:2019-06-20 22:01:47      阅读:137      评论:0      收藏:0      [点我收藏+]
function throttle(method, delay) {
    let timer,
        args = arguments,
        start;
    return function fn() {
        let self = this;
        let now = Date.now();
        if(!start){
            start = now;
        }
        if(timer){
            clearTimeout(timer);
        }
        if(now - start >= delay){
            method.apply(self, args);
            start = now;
        }else {
            timer = setTimeout(function () {
                console.log(args,‘args‘)
                fn.apply(self, args);
            }, delay);
        }
    }
}
function debounce(method,delay){
        let _delay = delay || 0;

        let timer = null;

        return function(){
            let args = arguments;


            timer && clearTimeout(timer);

            timer = setTimeout(()=>{
                method.apply(this,args)
            },_delay)
        }

      }

 

节流 防抖

原文:https://www.cnblogs.com/hill-foryou/p/11061224.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!