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
Add five buttons for testing the scrolling functions.

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
Step3:
js
Select the id of button and listen the click method.
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



Popular posts from this blog

Fancyapps — easily build overlay windows with carousel

Meet Tippy.js: The Complete Tooltip Popover Plugin

Meet Mantine: A TS-Based Open-Source React Components Library