summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-scroll-snap/capturing-snap-positions.html
blob: 7bc96b9d336646a32c79833fe5400557e0c7e06b (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
<!doctype html>
<meta charset=utf-8>
<title>scroll-snap-type on non-scrollers traps snap positions</title>
<link rel=author title="Tab Atkins-Bittner" href="https://www.xanthir.com/contact/">
<link rel="help" href="https://drafts.csswg.org/css-scroll-snap/#captures-snap-positions">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>

.scroller {
  width: 100px;
  height: 100px;
  overflow: auto;
  scroll-snap-type: block mandatory;
}
.item {
  background: gray;
  height: 100px;
  scroll-snap-type: block mandatory;
}
.item.snapped {
  background: green;
  scroll-snap-align: center;
}
.subitem {
  background: red;
  height: 100px;
  scroll-snap-align: center;
}

</style>


<!--
Boxes with a non-none value for scroll-snap-type
will capture snap positions from their descendents,
preventing them from affecting higher-up scrollers,
even if they are not, themselves, scrollers.
-->

<div class=scroller>
  <div class=item></div>
  <div class=item><div class=subitem></div></div>
  <div class="item snapped"></div>
  <div class=item></div>
</div>

<script>

test(()=>{
  const el = document.querySelector('.scroller');
  assert_equals(el.scrollTop, 200);
}, "The third item should be snapped to by default, not the second's child.");

</script>