Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /scroll-animations/view-timelines/view-timeline-relative-ancestor.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html id="top">
<head>
<meta charset="utf-8">
<title>View timeline with a relatively positioned ancestor</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<script src="/scroll-animations/scroll-timelines/testcommon.js"></script>
<script src="/scroll-animations/view-timelines/testcommon.js"></script>
<style>
#container {
height: 500px;
overflow: auto;
}
.space {
height: 550px;
}
/* The subject is statically positioned; the displacement comes from here. */
#wrapper {
position: relative;
top: 300px;
}
#target {
background: orange;
height: 100px;
}
</style>
</head>
<body>
<div id="container">
<div class="space"></div>
<div class="space">
<div style="height: 100px"></div>
<div id="wrapper">
<div style="height: 50px"></div>
<div id="target">Subject</div>
</div>
</div>
<div class="space"></div>
</div>
<script type="text/javascript">
// Same used position (1000px) as view-timeline-relative-subject.html, but the
// relative offset is on an ancestor rather than on the subject itself, so the
// expected ranges are identical.
//
// STATIC_POSITION = scroll distance to second spacer (550px)
// + position of the wrapper within it (100px)
// + position of the subject within the wrapper (50px)
const STATIC_POSITION = 700;
const RELATIVE_OFFSET = 300;
const USED_POSITION = STATIC_POSITION + RELATIVE_OFFSET;
const TARGET_HEIGHT = 100;
const VIEWPORT_HEIGHT = 500;
const START = USED_POSITION - VIEWPORT_HEIGHT;
const END = USED_POSITION + TARGET_HEIGHT;
promise_test(async t => {
await runTimelineRangeTest(t, {
rangeStart: { rangeName: 'cover', offset: CSS.percent(0) },
rangeEnd: { rangeName: 'cover', offset: CSS.percent(100) },
startOffset: START,
endOffset: END,
axis: 'block'
});
await runTimelineRangeTest(t, {
rangeStart: { rangeName: 'contain', offset: CSS.percent(0) },
rangeEnd: { rangeName: 'contain', offset: CSS.percent(100) },
startOffset: START + TARGET_HEIGHT,
endOffset: END - TARGET_HEIGHT,
axis: 'block'
});
await runTimelineRangeTest(t, {
rangeStart: { rangeName: 'entry', offset: CSS.percent(0) },
rangeEnd: { rangeName: 'entry', offset: CSS.percent(100) },
startOffset: START,
endOffset: START + TARGET_HEIGHT,
axis: 'block'
});
await runTimelineRangeTest(t, {
rangeStart: { rangeName: 'entry-crossing', offset: CSS.percent(0) },
rangeEnd: { rangeName: 'entry-crossing', offset: CSS.percent(100) },
startOffset: START,
endOffset: START + TARGET_HEIGHT,
axis: 'block'
});
await runTimelineRangeTest(t, {
rangeStart: { rangeName: 'exit', offset: CSS.percent(0) },
rangeEnd: { rangeName: 'exit', offset: CSS.percent(100) },
startOffset: END - TARGET_HEIGHT,
endOffset: END,
axis: 'block'
});
await runTimelineRangeTest(t, {
rangeStart: { rangeName: 'exit-crossing', offset: CSS.percent(0) },
rangeEnd: { rangeName: 'exit-crossing', offset: CSS.percent(100) },
startOffset: END - TARGET_HEIGHT,
endOffset: END,
axis: 'block'
});
}, 'View timeline with a relatively positioned ancestor, block axis.');
</script>
</body>
</html>