Skip to content

Instantly share code, notes, and snippets.

@hadnazzar
Created September 14, 2018 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadnazzar/73f3ff0cd4594007f0dfb5541c9e8bc6 to your computer and use it in GitHub Desktop.
Save hadnazzar/73f3ff0cd4594007f0dfb5541c9e8bc6 to your computer and use it in GitHub Desktop.
Vertical scroll on page
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