<main>
<!-- Significant content -->
</main>Document: scrollsnapchanging event / notebook
Document: scrollsnapchanging event
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
main {
width: 250px;
height: 450px;
overflow: scroll;
}html {
scroll-snap-type: block mandatory;
}document.addEventListener("scrollsnapchanging", (event) => {
// remove previously-set "pending" classes
const pendingElems = document.querySelectorAll(".pending");
pendingElems.forEach((elem) => {
elem.classList.remove("pending");
});
// Set current pending snap target class to "pending"
event.snapTargetBlock.classList.add("pending");
});