-
Notifications
You must be signed in to change notification settings - Fork 5
/
css-scroll-snap.html
101 lines (97 loc) · 2.57 KB
/
css-scroll-snap.html
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<title>Scroll Snap Demo</title>
<style>
.gallery {
height: 150px;
width: 150px;
border: 1px solid black;
scroll-padding: 10px;
}
.flex {
display: flex;
align-items: center;
}
.grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.horizontal {
scroll-snap-type: x mandatory;
overflow-x: scroll;
overflow-y: hidden;
}
.vertical {
scroll-snap-type: y mandatory;
overflow-x: hidden;
overflow-y: scroll;
}
.both {
scroll-snap-type: both mandatory;
overflow-x: scroll;
overflow-y: scroll;
}
.item {
width: 50px;
height: 50px;
background-color: grey;
flex-shrink: 0;
margin: 15px;
padding: 10px;
scroll-margin: 10px;
}
.snap-align-center {
scroll-snap-align: center;
}
.snap-align-start {
scroll-snap-align: start;
}
.snap-align-end {
scroll-snap-align: end;
}
.rtl {
direction: rtl;
}
.wm-vertical-lr {
writing-mode: vertical-lr;
}
</style>
<h3>Mixed snap-align with horizontal scroll</h3>
<div class="gallery horizontal flex">
<div class="item snap-align-start">A</div>
<div class="item snap-align-center">B</div>
<div class="item snap-align-center">C</div>
<div class="item snap-align-end">D</div>
</div>
<h3>Mixed snap-align with vertical scroll</h3>
<div class="gallery vertical">
<div class="item snap-align-start">A</div>
<div class="item snap-align-center">B</div>
<div class="item snap-align-center">C</div>
<div class="item snap-align-end">D</div>
</div>
<h3>Mixed snap-align with horizontal scroll and RTL direction</h3>
<div class="gallery horizontal rtl flex">
<div class="item snap-align-start">A</div>
<div class="item snap-align-center">B</div>
<div class="item snap-align-center">C</div>
<div class="item snap-align-end">D</div>
</div>
<h3>Mixed snap-align with horizontal scroll and writing mode</h3>
<div class="gallery horizontal wm-vertical-lr">
<div class="item snap-align-start">A</div>
<div class="item snap-align-center">B</div>
<div class="item snap-align-center">C</div>
<div class="item snap-align-end">D</div>
</div>
<h3>Mixed snap types</h3>
<div class="gallery grid both">
<div class="item snap-align-start">A</div>
<div class="item snap-align-center">B</div>
<div class="item snap-align-center">C</div>
<div class="item snap-align-center">D</div>
<div class="item snap-align-center">E</div>
<div class="item snap-align-center">F</div>
<div class="item snap-align-center">G</div>
<div class="item snap-align-center">H</div>
<div class="item snap-align-end">I</div>
</div>