Created
November 19, 2025 02:59
-
-
Save froger-me/749532ef1359dfc7cfbb4a9a3938764c to your computer and use it in GitHub Desktop.
A smooth scroll to use in devtools console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| setTimeout(() => { | |
| const targetScrollY = document.body.scrollHeight - window.innerHeight; | |
| const currentScrollY = window.pageYOffset; | |
| const distance = targetScrollY - currentScrollY; | |
| if (distance <= 0) return; // already at or past the bottom | |
| const speed = 50; // pixels per second — decrease this to make it slower | |
| const duration = (distance / speed) * 1000; // total time in milliseconds | |
| const startTime = performance.now(); | |
| function step(currentTime) { | |
| const elapsed = currentTime - startTime; | |
| const progress = Math.min(elapsed / duration, 1); | |
| const scrollTop = currentScrollY + distance * progress; | |
| window.scrollTo(0, scrollTop); | |
| if (progress < 1) { | |
| requestAnimationFrame(step); | |
| } | |
| } | |
| requestAnimationFrame(step); | |
| }, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment