-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathoverflowing-snap-areas.html
153 lines (139 loc) · 4.99 KB
/
overflowing-snap-areas.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-scroll-snap-1" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
div {
position: absolute;
}
.scroller-x {
overflow: scroll;
scroll-snap-type: x mandatory;
width: 500px;
height: 500px;
}
.scroller-y {
overflow: scroll;
scroll-snap-type: y mandatory;
width: 500px;
height: 500px;
}
.space {
width: 4000px;
height: 4000px;
}
.target {
scroll-snap-align: start;
}
.large-x {
width: 3000px;
height: 400px;
background-color: yellow;
}
.large-y {
width: 400px;
height: 2000px;
background-color: green;
}
.small {
height: 200px;
width: 200px;
background-color: black;
}
</style>
<div class="scroller-x" id="one-target">
<div id="space"></div>
<div class="large-x target" id="single" style="left: 200px;"></div>
</div>
<div class="scroller-x" id="x">
<div class="space"></div>
<div style="left: 200px;">
<div class="target large-x"></div>
<div class="target small" style="left: 200px"></div>
<div class="target small" style="left: 600px"></div>
<div class="target small" style="left: 1200px"></div>
</div>
</div>
<div class="scroller-y" id="y">
<div class="space"></div>
<div style="top: 200px;">
<div class="target large-y"></div>
<div class="target small" style="top: 200px"></div>
<div class="target small" style="top: 600px"></div>
<div class="target small" style="top: 1200px"></div>
</div>
</div>
<div class="scroller-x" id="two-axes" style="scroll-snap-type: both mandatory">
<div class="space"></div>
<div class="target large-x" style="top: 200px"></div>
</div>
<script>
var one_target_scroller = document.getElementById("one-target");
var scroller_x = document.getElementById("x");
var scroller_y = document.getElementById("y");
var two_axes_scroller = document.getElementById("two-axes");
test(() => {
one_target_scroller.scrollTo(10, 0);
assert_equals(one_target_scroller.scrollLeft, 200);
assert_equals(one_target_scroller.scrollTop, 0);
}, "Snaps to the snap position if the snap area doesn't cover the snapport on x.");
test(() => {
var right_align = 3200 - one_target_scroller.clientWidth;
one_target_scroller.scrollTo(right_align, 0);
assert_equals(one_target_scroller.scrollLeft, right_align);
assert_equals(one_target_scroller.scrollTop, 0);
}, "Snaps to the snap position if the snap area covers the snapport on x on the right border.");
// We use end alignment for this test so that we don't fall on a snap
// position when the snap area just covers the snapport on the left border.
test(() => {
document.getElementById("single").style.scrollSnapAlign = 'end';
one_target_scroller.scrollTo(200, 0);
assert_equals(one_target_scroller.scrollLeft, 200);
assert_equals(one_target_scroller.scrollTop, 0);
}, "Snaps to the snap position if the snap area covers the snapport on x on the left border.");
test(() => {
scroller_x.scrollTo(500, 0);
assert_equals(scroller_x.scrollLeft, 400);
assert_equals(scroller_x.scrollTop, 0);
}, "Snaps if the distance between the previous(400) and next(800) " +
"snap positions is smaller than snapport(500) on x.");
test(() => {
scroller_y.scrollTo(0, 500);
assert_equals(scroller_y.scrollLeft, 0);
assert_equals(scroller_y.scrollTop, 400);
}, "Snaps if the distance between the previous(400) and next(800) " +
"snap positions is smaller than snapport(500) on y.");
test(() => {
scroller_x.scrollTo(900, 0);
assert_equals(scroller_x.scrollLeft, 900);
assert_equals(scroller_x.scrollTop, 0);
}, "Snap to current scroll position which is a valid snap position, " +
"as the snap area covers snapport on x and the distance between the " +
"previous(800) and next(1400) is larger than snapport(500).");
test(() => {
scroller_y.scrollTo(0, 900);
assert_equals(scroller_y.scrollLeft, 0);
assert_equals(scroller_y.scrollTop, 900);
}, "Snap to current scroll position which is a valid snap position, " +
"as the snap area covers snapport on y and the distance between the " +
"previous(800) and next(1400) is larger than snapport(500).");
test(() => {
scroller_x.scrollTo(1500, 0);
assert_equals(scroller_x.scrollLeft, 1500);
assert_equals(scroller_x.scrollTop, 0);
}, "Snap to current scroll position which is a valid snap position, as the " +
"snap area covers snapport on x and there is no subsequent snap positions.");
test(() => {
scroller_y.scrollTo(0, 1500);
assert_equals(scroller_y.scrollLeft, 0);
assert_equals(scroller_y.scrollTop, 1500);
}, "Snap to current scroll position which is a valid snap position, as the " +
"snap area covers snapport on y and there is no subsequent snap positions.");
test(() => {
two_axes_scroller.scrollTo(10, 100);
assert_equals(two_axes_scroller.scrollLeft, 10);
assert_equals(two_axes_scroller.scrollTop, 200);
}, "Snap to current scroll position on x as the area is covering x axis." +
"However, we snap to the specified snap position on y as the area is not " +
"covering y axis.");
</script>