首页 > 其他 > 详细

节流和防抖

时间:2019-09-18 22:33:00      阅读:81      评论:0      收藏:0      [点我收藏+]
<script>
//防抖
var timer = null;
document.onscroll = function(){
    clearTimeout(timer)
   timer = setTimeout(()=>{
    console.log(111);
   },500)
}

//节流
var firstTime = 0;
document.onscroll = function(){
    var lastTime = new Date().getTime();

    if(lastTime - firstTime>500){
        console.log(111);
        firstTime = new Date().getTime();
    }
   
}
</script>

  

节流和防抖

原文:https://www.cnblogs.com/r-mp/p/11545527.html

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