Document: scrollend event

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The scrollend event fires when the document view has completed scrolling. 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 an element is complete, see the scrollend event of Element.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js
addEventListener("scrollend", (event) => {});

onscrollend = (event) => {};

Event type

A generic Event.

Examples

Using Document scrollend with an event listener

The following example shows how to use the scrollend event with an event listener to detect when the user has stopped scrolling the document. In the example, there is content in the embedded iframe that is taller and wider than the iframe itself, so scrolling within the iframe in both directions is possible. When the user stops scrolling, the scrollend event fires:

html
<div class="box-wrapper">
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
</div>
<p id="output">Waiting on scroll events...</p>
js
const output = document.querySelector("p#output");

document.addEventListener("scroll", (event) => {
  output.textContent = "Document scroll event fired!";
});

document.addEventListener("scrollend", (event) => {
  output.textContent = "Document scrollend event fired!";
});

Using onscrollend event handler property

The following example shows how to use the scrollend event handler property to detect when the user has stopped scrolling the document. In the example, there is content in the embedded iframe that is taller and wider than the iframe itself, so scrolling within the iframe in both directions is possible. This builds on the first example, but uses document.onscrollend instead of an event listener:

html
<div class="box-wrapper">
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
</div>
<p id="output">Waiting on scroll events...</p>
js
document.onscroll = (event) => {
  output.textContent = "Document scroll event fired!";
};

document.onscrollend = (event) => {
  output.textContent = "Document scrollend event fired!";
};

Specifications

Specification
CSSOM View Module
# eventdef-document-scrollend
HTML
# handler-onscrollend

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
scrollend event

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

See also