1. 交互
  2. 滚动捕捉停止

交互

scroll-snap-stop

用于控制是否可以跳过可能的快照位置的工具。

ClassStyles
snap-normal
scroll-snap-stop: normal;
snap-always
scroll-snap-stop: always;

示例

强制快照位置停止

snap-always 工具与 snap-mandatory 工具结合使用,以强制快照容器在用户继续滚动到下一个项目之前始终停在一个元素上:

在图像网格中滚动以查看预期行为

快照点
<div class="snap-x snap-mandatory ...">
<div class="snap-center snap-always ...">
<img src="/img/vacation-01.jpg" />
</div>
<div class="snap-center snap-always ...">
<img src="/img/vacation-02.jpg" />
</div>
<div class="snap-center snap-always ...">
<img src="/img/vacation-03.jpg" />
</div>
<div class="snap-center snap-always ...">
<img src="/img/vacation-04.jpg" />
</div>
<div class="snap-center snap-always ...">
<img src="/img/vacation-05.jpg" />
</div>
<div class="snap-center snap-always ...">
<img src="/img/vacation-06.jpg" />
</div>
</div>

跳过快照位置停止

使用 snap-normal 工具允许快照容器跳过可能的滚动快照位置:

在图像网格中滚动以查看预期行为

快照点
<div class="snap-x ...">
<div class="snap-center snap-normal ...">
<img src="/img/vacation-01.jpg" />
</div>
<div class="snap-center snap-normal ...">
<img src="/img/vacation-02.jpg" />
</div>
<div class="snap-center snap-normal ...">
<img src="/img/vacation-03.jpg" />
</div>
<div class="snap-center snap-normal ...">
<img src="/img/vacation-04.jpg" />
</div>
<div class="snap-center snap-normal ...">
<img src="/img/vacation-05.jpg" />
</div>
<div class="snap-center snap-normal ...">
<img src="/img/vacation-06.jpg" />
</div>
</div>

响应式设计

Prefix a scroll-snap-stop utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<div class="snap-always md:snap-normal ...">
<!-- ... -->
</div>

Learn more about using variants in the variants documentation.