Element: scrollend event
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Thescrollend event fires when element scrolling has completed.Scrolling is considered completed when the scroll position has no more pending updates and the user has completed their gesture.
Scroll position updates include smooth or instant mouse wheel scrolling, keyboard scrolling, scroll-snap events, or other APIs and gestures which cause the scroll position to update.User gestures like touch panning or trackpad scrolling aren't complete until pointers or keys have released.If the scroll position did not change, then no scrollend event fires.
For detecting when scrolling inside a Document is complete, see thescrollend event ofDocument.
In this article
Syntax
Use the event name in methods likeaddEventListener(), or set an event handler property.
addEventListener("scrollend", (event) => { })onscrollend = (event) => { }Event type
A genericEvent.
Example
>Usingscrollend with an event listener
The following example shows how to use thescrollend event to detect when the user has stopped scrolling:
#scroll-box { height: 100px; width: 100px; float: left; overflow: scroll; outline: 4px dotted; margin: 4px;}#scroll-box-title { position: fixed; top: 5px; left: 5px; transform: translateX(0);}#large-element { height: 200px; width: 200px;}#output { text-align: center;}<div> <p>Scroll me!</p> <p></p></div><p>Waiting on scroll events...</p>const element = document.querySelector("div#scroll-box");const output = document.querySelector("p#output");element.addEventListener("scroll", (event) => { output.textContent = "scroll event fired, waiting for scrollend...";});element.addEventListener("scrollend", (event) => { output.textContent = "scrollend event fired!";});Usingonscrollend event handler property
The following example shows how to use theonscrollend event handler property to detect when the user has stopped scrolling:
#scroll-box { height: 100px; width: 100px; float: left; overflow: scroll; outline: 4px dotted; margin: 4px;}#scroll-box-title { position: fixed; top: 5px; left: 5px; transform: translateX(0);}#large-element { height: 200px; width: 200px;}#output { text-align: center;}<div> <p>Scroll me!</p> <p></p></div><p>Waiting on scroll events...</p>const element = document.querySelector("div#scroll-box");const output = document.querySelector("p#output");element.onscroll = (event) => { output.textContent = "Element scroll event fired, waiting for scrollend...";};element.onscrollend = (event) => { output.textContent = "Element scrollend event fired!";};Specifications
| Specification |
|---|
| CSSOM View Module> # eventdef-document-scrollend> |
| HTML> # handler-onscrollend> |