Created
September 14, 2018 15:28
-
-
Save hadnazzar/73f3ff0cd4594007f0dfb5541c9e8bc6 to your computer and use it in GitHub Desktop.
Vertical scroll on page
This file contains 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
window.requestAnimationFrame(function step(timestamp) { | |
if (!start) start = timestamp; | |
// Elapsed milliseconds since start of scrolling. | |
let time = timestamp - start; | |
// Get percent of completion in range [0, 1]. | |
let percent = Math.min(time / duration, 1); | |
window.scrollTo(0, startingY + diff * percent); | |
// Proceed with animation as long as we wanted it to. | |
if (time < duration) { | |
window.requestAnimationFrame(step); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment