summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-anchor-position/position-fallback-bounds-004.html
blob: ff982ea93e49f666a254ea6704332c576c7842bc (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
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
92
93
94
95
96
97
98
<!DOCTYPE html>
<title>Tests complex interaction between 'position-fallback-bounds' and scrolling</title>
<link rel="help" href="https://drafts.csswg.org/css-anchor-position-1/#fallback-bounds">
<link rel="author" href="mailto:xiaochengh@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/test-common.js"></script>

<style>
body {
  margin: 0;
}

#anchor-scroller {
  position: absolute;
  height: 175px;
  width: 200px;
  left: 200px;
  top: 100px;
  overflow-y: scroll;
  z-index: 100;
}

#anchor {
  position: absolute;
  width: 100px;
  height: 100px;
  left: 0;
  top: 150px;
  background-color: orange;
  anchor-name: --a;
}

#bounds-scroller {
  position: absolute;
  width: 400px;
  height: 400px;
  left: 100px;
  top: 0;
  overflow-y: scroll;
}

#bounds {
  position: absolute;
  width: 400px;
  height: 400px;
  top: 100px;
  background: gray;
  anchor-name: --bounds;
}

#target {
  position: fixed;
  width: 100px;
  height: 100px;
  background-color: lime;
  left: anchor(left);
  anchor-default: --a;
  position-fallback-bounds: --bounds;
  position-fallback: --top-then-bottom;
}

@position-fallback --top-then-bottom {
  @try { bottom: anchor(top); }
  @try { top: anchor(bottom); }
}
</style>

<div id="anchor-scroller">
  <div id="anchor"></div>
</div>

<div id="bounds-scroller">
  <div id="bounds"></div>
</div>

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

<script>
promise_test(async () => {
  await waitUntilNextAnimationFrame();
  assert_fallback_position(target, anchor, 'top');
}, 'Target is above anchor at initial scroll position');

promise_test(async () => {
  const anchorScroller = document.getElementById('anchor-scroller');
  anchorScroller.scrollTop = 100;
  await waitUntilNextAnimationFrame();
  assert_fallback_position(target, anchor, 'bottom');
}, 'Target falls back to below anchor after anchor is scrolled upwards');

promise_test(async () => {
  const boundsScroller = document.getElementById('bounds-scroller');
  boundsScroller.scrollTop = 100;
  await waitUntilNextAnimationFrame();
  assert_fallback_position(target, anchor, 'top');
}, 'Target returns to above anchor after bounds are scrolled upwards');
</script>