DOM Window: scroll event
The scroll event fires when the page or a scrollable element is scrolled.
Description
The scroll event fires when the document or an element is scrolled. It fires very often, so keep handlers quick and pass { passive: true }. For effects tied to elements entering the screen, IntersectionObserver is far more efficient, and CSS scroll-driven animations can replace many scroll handlers entirely. The scrollend event fires once scrolling stops.
The event fires after the scroll has happened, so calling preventDefault() can't stop scrolling; to block scrolling, use CSS such as overflow: hidden. Scroll events on elements don't bubble, so listen on the scrolling element itself, or on the document with the capture option.
Listeners for window events are added with window.addEventListener(). The older way, assigning a function to a property such as window.onresize, only allows one handler, so a second assignment replaces the first.
Syntax
window.addEventListener('scroll', handler, { passive: true })Example
Browser Support
The following information will show you the current browser support for the Window: scroll event event. Hover over a browser icon to see the version that first introduced support for this event.
Desktop





Tablets & Mobile





