Get distance from top using Document.documentElement or Document.body and Element.scrollTop.
Navigation
Return the scroll position of the current page
Use Window.pageXOffset and Window.pageYOffset if they are defined, otherwise Element.scrollLeft and Element.scrollTop.
Scroll to an element smoothly (smooth scroll)
We can scroll to given element smoothly (smooth scroll) by passing behavior: ‘smooth’.
Drag to scroll
This post shows you a simple way to allow users to scroll by dragging the element with vanilla JavaScript.
Check if touch events are supported
Check if ‘ontouchstart’ exists in window.
Scroll to an element smoothly
This snippet produces a smooth scrolling implementation which also allows us to customize the animation effect and duration.
Scroll to top of the page
Utilizing this snippet, you can add a button at the bottom of page that allows user to scroll to the top quickly.
Detecting when a visitor has stopped scrolling
This snippet listens for scroll events using addEventListener, sets a delayed timeout function to run a few milliseconds after the event, but with each scroll event it clears that timeout function so it doesn’t run.
Using the Target Attribute
Using this script, you will be able to keep your pages valid while also using the target attribute to open new windows.
Ticker
An attractive news bar script. Messages are automatically rotated and displayed, with the ability to manually cycle back and forth through them. This script was created entirely using form buttons. Works in most browsers!