aboutsummaryrefslogtreecommitdiffstats
path: root/tests/wpt/web-platform-tests/css/css-scroll-snap/snap-inline-block.html
blob: 9f9da8f648bfc0f873b339639bd18aba1e25b4c3 (plain) (blame)
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
<!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;
  margin: 0px;
}
#scroller {
  width: 400px;
  height: 350px;
  overflow: scroll;
  scroll-snap-type: both mandatory;
}
#space {
  width: 1000px;
  height: 1000px;
}
#target {
  width: 200px;
  height: 200px;
  left: 300px;
  top: 300px;
  scroll-snap-align: end start;
}
</style>

<div id="scroller">
  <div id="space"></div>
  <div id="target"></div>
</div>

<script>
var scroller = document.getElementById("scroller");
var width = scroller.clientWidth;
var height = scroller.clientHeight;
[
  ["horizontal-tb", 300, 500 - height],
  ["vertical-lr", 500 - width, 300],
  ["vertical-rl", width - 700, 300]
].forEach(([writing_mode, left, top]) => {
  test(() => {
    scroller.style.writingMode = writing_mode;
    if (writing_mode == "vertical-rl")
      document.getElementById("target").style.left = (width - 700) + "px";
    scroller.scrollTo(0, 0);
    assert_equals(scroller.scrollLeft, left, "aligns correctly on x");
    assert_equals(scroller.scrollTop, top, "aligns correctly on y");
  }, "Snaps correctly for " + writing_mode +
     " writing mode with 'inline' and 'block' alignments");
})
</script>