大网数据广告活动
Web 标准与前端开发

SnapEvent: snapTargetBlock property

· 52CE 我爱测

The **`snapTargetBlock`** read-only property of the SnapEvent interface returns a reference to the element snapped to in the block direction when the event fired.

Snap Events

The snapTargetBlock read-only property of the SnapEvent interface returns a reference to the element snapped to in the block direction when the event fired.

Specifically:

  • In the case of the Element/scrollsnapchanging_event event, this refers to a pending block-direction snap target (i.e., it will be selected when the current scroll gesture ends).
  • In the case of the Element/scrollsnapchange_event event, this refers to a newly-selected block-direction snap target.

The property values available on SnapEvent correspond directly to the value of the scroll-snap-type CSS property set on the scroll container. snapTargetBlock only returns an element reference if the snap axis is specified as block (or a physical axis value that equates to block in the current writing mode) or both.

Value

A Node representing the snapped element, or null if scroll snapping only occurs in the inline direction so no element is snapped to in the block direction.

If the snapped element was a pseudo-element, the returned Node will be the owning element of that pseudo-element.

Examples

See the main SnapEvent page for brief examples, and our Using scroll snap events guide for full examples and explanation.

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。