一行JS 实现 网页自动上下滚动

一行JS 实现 网页自动上下滚动(翻看长页面使用)
使用方法:F12 打开浏览器开发控制台点击 console标签,粘贴此代码回车执行即可 最后的1000 代表1秒可自行调整

let scrollDir = 100; setInterval(() => { const isBottom = window.innerHeight + window.scrollY >= document.documentElement.scrollHeight; const isTop = window.scrollY <= 0; if (isBottom) { scrollDir = -scrollDir; } else if (isTop && scrollDir < 0) { scrollDir = Math.abs(scrollDir); } window.scrollBy(0, scrollDir); }, 1000);

posted @ 2024-02-05 15:01  Ai喝咖啡Demo  阅读(339)  评论(0)    收藏  举报