防抖

发布时间 2023-05-09 10:12:04作者: Imzzk
<script>
function Test(fn,delay){

  let timer = null;
  return function () {
  if(timer){
    clearTimeout(timer);
  }
  timer = setTimeout(fn,delay);

  }

}

window.onscroll=Test(scrollHandle,200);
function scrollHandle(){
   let scrollTop = document.documentElement.scrollTop;
   console.log(scrollTop);

}

</script>