summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-scroll-snap/scroll-snap-type-change.html
blob: ed86bace4473f9b234e3b6f6ff0a3940bd980a37 (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
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-scroll-snap/#scroll-snap-type" />
<meta name="viewport" content="user-scalable=no">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
div, html, body {
  margin: 0;
  padding: 0;
}
html {
  margin: 0px;
  overflow: scroll;
}
#scroller {
  margin-left: 200px;

  height: 300px;
  width: 300px;
  overflow: scroll;
}
.space {
  width: 2000px;
  height: 2000px;
}
.snap_area {
  margin-left: 200px;
  top: 0;
  width: 200px;
  height: 200px;
  background-color: blue;
  scroll-snap-align: none start;
}
</style>

<!-- Add snap area to the root scroller -->
<div class="snap_area" id="viewport"></div>

<div id="scroller">
  <div class="snap_area" id="inner"></div>
  <div class="space"></div>
</div>

<div class="space"></div>

<script>

const scrollers = [document.scrollingElement, document.getElementById("scroller")];
for (const scroller of scrollers) {
  test(_ => {
    scroller.style.scrollSnapType = 'x mandatory';
    scroller.scrollTo(100, 0);
    assert_equals(scroller.scrollLeft, 200, "scrolling should snap");

    // When snap type is 'none' the scroller, scrolling should not snap.
    scroller.style.scrollSnapType = 'none';
    scroller.scrollTo(100, 0);
    assert_equals(scroller.scrollLeft, 100, "scrolling should not snap");

    // When snap type is changed back to mandatory, scrolling should snap.
    scroller.style.scrollSnapType = 'x mandatory';
    scroller.scrollTo(110, 0);
    assert_equals(scroller.scrollLeft, 200, "scrolling should snap after change");
  }, `scroll-snap-type on ${scroller.nodeName} should control snapping behavior and changing it takes effect`);
}
</script>