summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-anchor-position/anchor-transition-001.html
blob: e69a38820518289b769864fd6c85b30c0df3ce12 (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
<!DOCTYPE html>
<title>Tests CSS transition of anchor() and anchor-size() functions</title>
<link rel="help" href="https://drafts4.csswg.org/css-anchor-position-1/">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/8180"></script>
<link rel="author" href="mailto:xiaochengh@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<style>
body {
  margin: 0;
}

#anchor1 {
  margin-left: 0px;
  margin-top: 0px;
  width: 200px;
  height: 100px;
  background: orange;
  anchor-name: --a1;
}

#anchor2 {
  margin-left: 400px;
  margin-top: 200px;
  width: 100px;
  height: 200px;
  background: orange;
  anchor-name: --a2;
}

#target {
  position: fixed;
  width: 100px;
  height: 100px;
  background-color: lime;
  transition: all 10s -5s linear;
}

#target.before {
  top: anchor(--a1 top);
  left: anchor(--a1 right);
  width: anchor-size(--a1 width);
  height: anchor-size(--a1 height);
}

#target.after {
  top: anchor(--a2 bottom);
  left: anchor(--a2 left);
  width: anchor-size(--a2 width);
  height: anchor-size(--a2 height);
}
</style>

<div id="anchor1"></div>
<div id="anchor2"></div>
<div id="target" class="before"></div>

<script>
setup(() => {
  // Forces layout
  target.offsetLeft;
  // Triggers transition starting at 50% immediately
  target.classList.remove('before');
  target.classList.add('after');
});

test(() => {
  assert_equals(target.offsetLeft, 300);
  assert_equals(target.offsetTop, 250);
}, 'Transition of anchor() when changing target anchor element name');

test(() => {
  assert_equals(target.offsetWidth, 150);
  assert_equals(target.offsetHeight, 150);
}, 'Transition of anchor-size() when changing target anchor element name');
</script>