交互
用于控制是否可以跳过可能的快照位置的工具。
Class | Styles |
---|---|
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.