blob: d04cacb50cc5c079527ade7f03a03799c36d752c [file] [log] [blame]
<!DOCTYPE html>
<title>@container: scroll-state(scrolled) state is persisted across horizontal and vertical scrolling</title>
<link rel="help" href="https://drafts.csswg.org/css-conditional-5/#scrolled">
<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>
#scroller {
width: 200px;
height: 200px;
container-type: scroll-state;
overflow: scroll;
}
#filler {
height: 600px;
width: 600px;
}
#target {
--top: no;
--bottom: no;
--left: no;
--right: no;
--none: no;
@container scroll-state(scrolled: top) {
--top: yes;
}
@container scroll-state(scrolled: bottom) {
--bottom: yes;
}
@container scroll-state(scrolled: left) {
--left: yes;
}
@container scroll-state(scrolled: right) {
--right: yes;
}
@container scroll-state(scrolled: none) {
--none: yes;
}
}
</style>
<div id="scroller">
<div id="filler">
<div id="target"></div>
</div>
</div>
<script>
setup(() => assert_implements_scroll_state_container_queries());
promise_test(async t => {
await waitForAnimationFrames(2);
assert_equals(getComputedStyle(target).getPropertyValue("--none"), "yes");
assert_equals(getComputedStyle(target).getPropertyValue("--left"), "no");
assert_equals(getComputedStyle(target).getPropertyValue("--right"), "no");
assert_equals(getComputedStyle(target).getPropertyValue("--top"), "no");
assert_equals(getComputedStyle(target).getPropertyValue("--bottom"), "no");
}, "Check that scroll-state(scrolled) state before scrolling");
promise_test(async t => {
scroller.scrollBy(300, 0);
await waitForAnimationFrames(2);
scroller.scrollBy(0, 100);
await waitForAnimationFrames(2);
assert_equals(getComputedStyle(target).getPropertyValue("--left"), "no");
assert_equals(getComputedStyle(target).getPropertyValue("--right"), "yes");
assert_equals(scroller.scrollLeft, 300);
assert_equals(scroller.scrollTop, 100);
}, "Check that scroll-state(scrolled) horizontal state is persisted across vertical scroll event");
promise_test(async t => {
scroller.scrollBy(0, 100);
await waitForAnimationFrames(2);
scroller.scrollBy(0, -100);
await waitForAnimationFrames(2);
scroller.scrollBy(-200, 0);
await waitForAnimationFrames(2);
assert_equals(getComputedStyle(target).getPropertyValue("--top"), "yes");
assert_equals(getComputedStyle(target).getPropertyValue("--bottom"), "no");
assert_equals(scroller.scrollLeft, 100);
assert_equals(scroller.scrollTop, 100);
}, "Check that scroll-state(scrolled) vertical state is persisted across horizontal scroll event");
</script>