代码如下
<style> body { height: 200vh; } </style> <body> <script> /** * 监听页面滚动 * */ window.addEventListener('scroll', function () { var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop; console.log(scrollTop); }) </script> </body>