Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The SnapEvent() constructor creates a new SnapEvent object instance.
new SnapEvent(type, init)typeA string representing the type of event. For scrollsnapchanging events, this is scrollsnapchanging. For scrollsnapchange events, this is scrollsnapchange.
initAn object containing the following properties:
snapTargetBlock OptionalReturns a reference to the element snapped to in the block direction when the event fired, or null if scroll snapping only occurs in the inline direction so no element is snapped to in the block direction.
snapTargetInline OptionalReturns a reference to the element snapped to in the inline direction when the event fired, or null if scroll snapping only occurs in the block direction so no element is snapped to in the inline direction.
A developer would not use this constructor manually. A new SnapEvent object is constructed when a handler is invoked as a result of the scrollsnapchanging or scrollsnapchange events firing.
For example:
mainElem.addEventListener("scrollsnapchange", (event) => {
// …
// Log a SnapEvent object instance to the console
console.log(event);
});scrollsnapchanging eventscrollsnapchange event