时间:2023-03-06来源:系统城装机大师作者:佚名
sroll-snap-type:none | [ x | y | block | inline | both ] [ mandatory | proximity ]?
一般使用:
| 1 | scroll-snap-type: x mandatory; |
scroll-padding:定义滚动盒子的padding
注意正常的padding在scroll-snap中用来控制停止后相对滚动容器的位置会失效
scroll-snap-stop: normal | always
控制停止元素的行为,normal根据滚动距离计算要停止的元素,always:无视滚动距离,只会停止在下一个元素,比如滑动1000px还是停止在下一个元素
scroll-snap-align:start | center | end;
滚动停止后,元素所在的位置,类比justify-content 属性的 flex-start | flex-end | center
下面三个分别对应start | center | end,表示滚动结束后元素停止容器开头、中心、结尾

scroll-margin:定义某个子元素的margin
用于精细控制滚动停止后元素相对于滚动容器的位置
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<ul class="snap"> <li>1</li> <li>2</li> <li>3</li> ...</ul> .snap { overflow-x: auto; scroll-snap-type: y mandatory; scroll-padding-top: 30px;} li { scroll-snap-align: start;} |

代码示例:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> .section { height: 200px; width: 400px; display: flex; overflow-x: auto; scroll-snap-type: x mandatory; } .section__item { /* scroll-snap-align: start; */ height: 200px; width: 200px; margin: 0 100px; flex: none; scroll-padding-right: 40px; scroll-snap-align: end; } .section__item:nth-child(odd) { background: red; } .section__item:nth-child(even) { background: green; } </style></head><body> <div class="section"> <div class="section__item">Item 1</div> <div class="section__item">Item 2</div> <div class="section__item">Item 3</div> <div class="section__item">Item 4</div> <div class="section__item">Item 5</div> </div> <script> </script></body></html><font face="Tahoma"><span style="white-space: normal;"> </span></font> |
到此这篇关于css scroll-snap控制滚动元素的实现的文章就介绍到这了
2023-03-06
css3鼠标滑过实现动画线条边框2023-03-06
CSS实现多层嵌套列表自动编号的示例代码2023-03-06
纯CSS实现具有渐变和圆角的彩色边框今天给大家带来一个如何实现圆角三角形的方案,这个方案虽然可以实现,但是也是借助拼凑等方式来实现的,假如想一个div来实现圆角三角形,还是比较困难的。之前文章讲了如何实现对话框,里面介绍了三角形的实现方式。今天讲讲...
2023-03-06
Flex 简介 Flex 容器属性 Flex 基本使用 场景一 flex-direction 场景二 justify-content align-items flex-wrap...
2023-03-06