Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /scroll-animations/animation-trigger/trigger-scope-tree-order-ancestor-chain.tentative.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<head>
<link rel="help" src="https://drafts.csswg.org/css-animations-2/#trigger-scope">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<script src="/dom/events/scrolling/scroll_support.js"></script>
<script src="support/support.js"></script>
<script src="support/trigger-scope-support.js"></script>
</head>
<body>
<style>
@keyframes expand {
from { transform: scaleX(1) }
to { transform: scaleX(2) }
}
#scroller {
overflow-y: scroll;
height: 200px;
width: 200px;
border: solid 1px;
trigger-scope: all;
display: block;
position: relative;
}
.source {
top: 100%;
height: 100px;
width: 100px;
background-color: blue;
timeline-trigger: --trigger view() contain;
color: white;
}
.target {
background-color: red;
height: 100px;
width: 100px;
animation: expand linear 1s both;
animation-trigger: --trigger play-forwards;
position: sticky;
top: 0%;
left: 50%;
}
.long {
width: 50%;
height: 100%;
}
</style>
<div id="scroller">
<!-- This target does not have a trigger source in its ancestry. It -->
<!-- selects the last one in tree order, i.e. the one from source 5 -->
<div id="tree_order_target" class="target">Target</div>
<div class="long"></div>
<div id="source1" class="source">SOURCE 1
<div class="long"></div>
<div id="source2" class="source">SOURCE 2
<div class="long"></div>
<div id="source3" class="source">SOURCE 3
<!-- This target is a descendant of source3, so it selects the -->
<!-- trigger from source 3 -->
<div id="ancestor_chain_target" class="target">Target</div>
<div class="long"></div>
<div id="source4" class="source">SOURCE 4
<div class="long"></div>
<div id="source5" class="source">SOURCE 5</div>
<div class="long"></div>
</div>
</div>
</div>
</div>
</div>
<script>
function resetAnimations() {
tree_order_target.getAnimations()[0].pause();
ancestor_chain_target.getAnimations()[0].pause();
tree_order_target.getAnimations()[0].currentTime = 0;
ancestor_chain_target.getAnimations()[0].currentTime = 0;
}
async function test_source(source,
affects_tree_order_target,
affects_ancestor_chain_target) {
resetAnimations();
assert_element_animation_state(tree_order_target, "paused");
assert_element_animation_state(ancestor_chain_target, "paused");
// Scroll the trigger sources into view.
await runAndWaitForFrameUpdate(() => {
source.scrollIntoView({block: "center"});
});
assert_element_animation_state(tree_order_target,
affects_tree_order_target ? "running" : "paused");
assert_element_animation_state(ancestor_chain_target,
affects_ancestor_chain_target ? "running" : "paused");
}
promise_test(async() => {
// Sources 1 through 4 come earlier than source5 in tree-order so they
// should have no effect on tree_order_target.
// Source3 is an ancestor of ancesor_chain_target, so it should trigger
// ancestor_chain_target.
// 1 and 2 should affect neither.
await test_source(source1,
/*affects_tree_order_target=*/false,
/*affects_ancestor_chain_target=*/false);
await test_source(source2,
/*affects_tree_order_target=*/false,
/*affects_ancestor_chain_target=*/false);
// 3 should affect ancestor_chain_target.
await test_source(source3,
/*affects_tree_order_target=*/false,
/*affects_ancestor_chain_target=*/true);
// 4 should affect neither.
await test_source(source4,
/*affects_tree_order_target=*/false,
/*affects_ancestor_chain_target=*/false);
// 5 should affect tree_order_target.
await test_source(source5,
/*affects_tree_order_target=*/true,
/*affects_ancestor_chain_target=*/false);
}, "Among in-scope triggers with same name, last in tree-order is "+
"selected, unless name occurs in ancestry before scope is reached.");
</script>
</body>
</html>