Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<title>@container: scroll-state(scrollable) matching body</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/css-conditional/container-queries/support/cq-testcommon.js"></script>
<script src="/css/css-transitions/support/helper.js"></script>
<style>
html {
/* Make sure scrollbars are created on body and not propagated to viewport */
overflow: scroll;
}
body {
height: 500px;
overflow: scroll;
container-type: scroll-state;
}
#target {
height: 5000px;
--top: no;
--bottom: no;
@container scroll-state(scrollable: top) {
--top: yes;
}
@container scroll-state(scrollable: bottom) {
--bottom: yes;
}
}
</style>
<div id="target"></div>
<script>
setup(() => assert_implements_scroll_state_container_queries());
promise_test(async t => {
await waitForAnimationFrames(2);
assert_equals(getComputedStyle(target).getPropertyValue("--top"), "no");
assert_equals(getComputedStyle(target).getPropertyValue("--bottom"), "yes");
assert_equals(document.body.scrollTop, 0);
}, "Check that scroll-state(scrollable) matches bottom before scroll");
promise_test(async t => {
document.body.scrollTop = 100;
await waitForAnimationFrames(2);
assert_equals(getComputedStyle(target).getPropertyValue("--top"), "yes");
assert_equals(getComputedStyle(target).getPropertyValue("--bottom"), "yes");
}, "Check that scroll-state(scrollable) matches both top and bottom in a middle position");
promise_test(async t => {
document.body.scrollTop = 5000;
await waitForAnimationFrames(2);
assert_equals(getComputedStyle(target).getPropertyValue("--top"), "yes");
assert_equals(getComputedStyle(target).getPropertyValue("--bottom"), "no");
}, "Check that scroll-state(scrollable) matches both top when scrolled to the end");
</script>