<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>