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
|
<!DOCTYPE html>
<title>
A test case that scrolling to a point on large element where the snap area
doesn't cover over the snapport
</title>
<link rel="help" href="https://drafts.csswg.org/css-scroll-snap-1/#snap-overflow"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
div {
position: absolute;
width: 100%;
}
#scroller {
left: 10px;
height: 200px;
width: 100px;
overflow-y: scroll;
overflow-x: hidden;
scroll-snap-type: y mandatory;
}
.snap {
scroll-snap-align: start;
background-color: green;
}
.target {
background-color: red;
border-radius: 100%;
height: 88px;
top: 536px;
}
</style>
<div id="scroller">
<div style="height: 2000px;"></div>
<div class="snap" style="top: 0px; height: 40px;">1</div>
<div class="snap" style="top: 40px; height: 40px;">2</div>
<div class="snap" style="top: 80px; height: 1000px;">3</div>
<div class="snap" style="top: 1080px; height: 40px;">4</div>
<div class="snap" style="top: 1120px; height: 40px;">5</div>
<div class="target"></div>
</div>
<script>
test(() => {
const scroller = document.getElementById("scroller");
scroller.scrollBy(0, 10);
// Snap to the first snap point.
assert_equals(scroller.scrollLeft, 0);
assert_equals(scroller.scrollTop, 40);
scroller.scrollBy(0, 10);
// Snap to the second snap point.
assert_equals(scroller.scrollLeft, 0);
assert_equals(scroller.scrollTop, 80);
scroller.scrollBy(0, 100);
// Snap to the given scrolling position since the third snap target element
// is larger than the snapport.
assert_equals(scroller.scrollLeft, 0);
assert_equals(scroller.scrollTop, 180);
scroller.scrollBy(0, 100);
// Again, snap to the given scrolling position.
assert_equals(scroller.scrollLeft, 0);
assert_equals(scroller.scrollTop, 280);
// Scroll to a point where the third target element is still covering over the
// snapport.
scroller.scrollBy(0, 600);
assert_equals(scroller.scrollLeft, 0);
// Again, snap to the given scrolling position.
assert_equals(scroller.scrollTop, 880);
// Scroll to a point where the third target element is no longer convering
// over the snapport, rather the forth snap point is in the snapport.
scroller.scrollBy(0, 10);
// Now, snap to the forth snap point.
assert_equals(scroller.scrollLeft, 0);
assert_equals(scroller.scrollTop, 1080);
// Scroll back a bit.
scroller.scrollBy(0, -10);
// Now, snap back to the third snap point because at the moment when scrolling
// up by 10px, the large third snap target element isn't covering over the
// snapport, i.e. only bottom 10px of the large element is in the snapport.
// See https://github.com/w3c/csswg-drafts/issues/7262
assert_equals(scroller.scrollLeft, 0);
assert_equals(scroller.scrollTop, 80);
}, 'There\'s no valid snap positions on large element if it doesn\'t cover ' +
'the snapport');
</script>
|