Scroll Snap 参考

核心属性

属性取值应用于
scroll-snap-typex|y|both + mandatory|proximity滚动容器
scroll-snap-alignstart | center | end | none滚动子元素
scroll-paddingpx | rem | %(简写或各边)滚动容器
scroll-marginpx | rem滚动子元素
scroll-snap-stopnormal | always滚动子元素
overscroll-behaviorauto | contain | none滚动容器

横向 Scroll Snap(向右滚动)

纵向 Scroll Snap

代码示例

/* Horizontal carousel */ .carousel { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding: 0 16px; } .carousel-item { min-width: 80%; scroll-snap-align: start; scroll-snap-stop: always; } /* Vertical full-screen sections */ .sections { height: 100vh; overflow-y: scroll; scroll-snap-type: y mandatory; } .section { height: 100vh; scroll-snap-align: start; }