W3cubDocs

/Web APIs

SnapEvent: SnapEvent() constructor

Limited availability

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

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.

Syntax

new SnapEvent(type, init)

Parameters

type

A string representing the type of event. For scrollsnapchanging events, this is scrollsnapchanging. For scrollsnapchange events, this is scrollsnapchange.

init

An object containing the following properties:

snapTargetBlock Optional

Returns 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 Optional

Returns 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.

Examples

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);
});

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
SnapEvent 138 138 No 122 No 138 No No No No No No

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SnapEvent/SnapEvent