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-abspos-subject.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html id="top">
<head>
<meta charset="utf-8">
<title>View timeline with an absolutely positioned subject</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's containing block, inside the scroll container. */
#cb {
position: relative;
}
/* Its static position would be the top of #cb (550px); the used position is
550px + 450px. */
#target {
position: absolute;
top: 450px;
left: 0;
background: orange;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div id="container">
<div class="space"></div>
<div class="space" id="cb">
<div id="target"></div>
</div>
<div class="space"></div>
</div>
<script type="text/javascript">
// USED_POSITION = scroll distance to the containing block (550px)
// + the subject's `top` within it (450px)
const USED_POSITION = 1000;
const TARGET_HEIGHT = 100;
const VIEWPORT_HEIGHT = 500;
const START = USED_POSITION - VIEWPORT_HEIGHT;
const END = USED_POSITION + TARGET_HEIGHT;
promise_test(async t => {
const timeline = new ViewTimeline({ subject: target, axis: 'block' });
assert_equals(timeline.source, container, 'timeline source');
assert_px_equals(timeline.startOffset, START, 'startOffset');
assert_px_equals(timeline.endOffset, END, 'endOffset');
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 an absolutely positioned subject whose containing ' +
'block is inside the scroll container, block axis.');
</script>
</body>
</html>