May 19, 2020 by Andreas Wik
You can easily find out how far down on the page the user has scrolled by checking the window or document object.
So, depending on the browser, we can use either the pageYOffset property from the window object, or the scrollTop property from document.
Below I assign the value to a variable named scrollTop:
const scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop