Skip to content

Instantly share code, notes, and snippets.

@ajfarkas
Created January 4, 2015 00:21
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 ajfarkas/5fd142423ca86a39c522 to your computer and use it in GitHub Desktop.
Save ajfarkas/5fd142423ca86a39c522 to your computer and use it in GitHub Desktop.
Smooth Scroll for web in Vanilla JS
function scrollSmooth(node, time){
var distance = node.getBoundingClientRect().top,
step = 10 * distance / time,
frames = distance / step,
i = 0,
run;
function goTo(){
window.scrollBy(0, step);
i++;
if (i > frames) clearInterval(run);
}
run = setInterval(goTo, 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment