2023-08-21T14:59:44.png

<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <style>


h1{
height:500px;

}



  </style>

</head>
<body>
  
  



<h1>哈哈哈</h1>
<h1>哈哈哈</h1>
<h1>哈哈哈</h1>
<h1>哈哈哈</h1>
<h1>哈哈哈</h1>











<script>






function throttle(fn,delay){

  var valid = true;

  return function(){

    if(!valid){
      return false;


    }
    valid = false;

    setTimeout(function(){


      fn();

      valid = true;




    },delay)


  }



}









//滚动事件
window.onscroll = throttle(scrollHandle,2000);




function scrollHandle(){

  console.log("页面滚动了,高度为:");

var scrollTop = document.documentElement.scrollTop;

console.log(scrollTop);


};










</script>







</body>
</html>