smoothscroll.js---pure javascript smooth scrolling plugin
Smoothscroll.js is an extension of the window interface to allow for the developer to opt in to native smooth scrolling.
GitHub here
Step1:
link smoothscroll.js into body bottom
<script type="text/javascript" src="smoothscroll.js"></script>Step2:
html |
bottom is scrolling to bottom.
down is scrolling down by 500px.
up is scrolling up by 500px.
view is scrolling to the position you want.(here is to the paragraph)
top is scrolling back to top.
The basic styling below
css |
js |
Scroll to the position with top pixel and behavior smooth.
Methods:
1.
window.scroll or window.scrollTo . (to the position top 2500px)
window.scroll({ top: 2500, left: 0, behavior: 'smooth' });
2.window.scrollBy. (the position fixed)
window.scrollBy({ top: 100, left: 0, behavior: 'smooth' });
//or
window.scrollBy({ top: -100, left: 0, behavior: 'smooth' });
3.element.scrollIntoView.(scroll to the section you want)
document.querySelector('section id or class name').scrollIntoView({ behavior: 'smooth' });
Another return to top javascript demo here