How to create a pure Javascript function that works exactly like this?
$('html, body').animate({
scrollTop: y
}, 400);
Here y
is a parameter for vertical position to reach. In a site where I'm working now, there is a horizontal nav that is fixed in the top while scrolling and auto focuses corresponding menu item when it scrolls to the mapped section.
Also, when the menu item is clicked, body container should auto scroll to that section.
I could do this by using jQuery animation easily, but the client doesn't want to use jQuery anymore.
I have researched quite a few questions & answers on this site where window.requestAnimationFrame()
or CSS transition effect. But I could not find out a perfect solution.
Thanks.