blob: b8604269b4b9a1d6dbf337cfe867714cbf40fabb (
plain)
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
|
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-scroll-snap-1/#scroll-snap-type" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
div {
position: absolute;
}
#scroller {
overflow: hidden; /* TODO: Use scrollbar-width: none */
scroll-snap-type: x mandatory;
width: 500px;
height: 500px;
}
.space {
width: 2000px;
height: 2000px;
}
#target {
height: 200px;
width: 200px;
left: 50px;
background-color: blue;
}
</style>
<div id="scroller">
<div class="space"></div>
<div id="target"></div>
</div>
<script>
test(() => {
target.style.scrollSnapAlign = "start";
target.style.transform = "translateX(300px)";
scroller.scrollTo(10, 0);
assert_equals(scroller.scrollLeft, 350 /* left + translateX(300px) */);
assert_equals(scroller.scrollTop, 0);
}, "Snaps to the transformed snap start position");
test(() => {
target.style.scrollSnapAlign = "end";
target.style.transform = "translateX(300px)";
scroller.scrollTo(10, 0);
assert_equals(scroller.scrollLeft,
50 /* left + width + translateX(300px) - scroller.width */);
assert_equals(scroller.scrollTop, 0);
}, "Snaps to the transformed snap end position");
test(() => {
target.style.scrollSnapAlign = "start";
target.style.transform = "translateX(-100px)";
scroller.scrollTo(10, 0);
assert_equals(scroller.scrollLeft, 0);
assert_equals(scroller.scrollTop, 0);
}, "Snaps to visible top left position of the transformed box");
</script>
|