Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /css/css-anchor-position/position-area-scrolling-007.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>position-try-fallbacks with flip-block and flip-inline</title>
<link rel="author" title="Morten Stenshorne" href="mailto:mstensho@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/test-common.js"></script>
<style>
#anchor {
anchor-name: --a;
margin-top: 200px;
margin-left: 100px;
width: 150px;
height: 50px;
background: blue;
}
#anchored {
position: absolute;
position-anchor: --a;
position-area: top left;
position-try-fallbacks: flip-inline, flip-block, flip-block flip-inline;
width: 100%;
height: 100%;
min-width: 60px;
min-height: 60px;
background: hotpink;
}
</style>
<div style="position:relative; width:400px; height:400px;">
<div id="scroller" style="overflow:scroll; scrollbar-width:none; width:100%; height:100%;">
<div id="anchor"></div>
<div style="width:1000px; height:1000px;"></div>
<div id="anchored"></div>
</div>
</div>
<script>
promise_test(async () => {
await waitUntilNextAnimationFrame();
await waitUntilNextAnimationFrame();
assert_equals(anchored.offsetLeft, 0);
assert_equals(anchored.offsetTop, 0);
assert_equals(anchored.offsetWidth, 100);
assert_equals(anchored.offsetHeight, 200);
}, 'initial position');
promise_test(async () => {
scroller.scrollTo(0, 150);
await waitUntilNextAnimationFrame();
await waitUntilNextAnimationFrame();
assert_equals(anchored.offsetLeft, 0);
assert_equals(anchored.offsetTop, 100);
assert_equals(anchored.offsetWidth, 100);
assert_equals(anchored.offsetHeight, 300);
}, 'Scroll down to 0,150');
promise_test(async () => {
scroller.scrollTo(50, 150);
await waitUntilNextAnimationFrame();
await waitUntilNextAnimationFrame();
assert_equals(anchored.offsetLeft, 200);
assert_equals(anchored.offsetTop, 100);
assert_equals(anchored.offsetWidth, 200);
assert_equals(anchored.offsetHeight, 300);
}, 'Scroll right to 50,150');
promise_test(async () => {
scroller.scrollTo(50, 0);
await waitUntilNextAnimationFrame();
await waitUntilNextAnimationFrame();
assert_equals(anchored.offsetLeft, 200);
assert_equals(anchored.offsetTop, 250);
assert_equals(anchored.offsetWidth, 200);
assert_equals(anchored.offsetHeight, 150);
}, 'Scroll up to 50,0');
</script>