Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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