Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<html id="top">
<head>
<meta charset="utf-8">
<title>View timeline with a relatively 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 inline-axis offset must not affect the block-axis ranges. */
#target {
position: relative;
top: 300px;
left: 40px;
background: orange;
width: 100px;
height: 100px;
}
#target.shifted-back {
top: -200px;
}
</style>
</head>
<body>
<div id="container">
<div class="space"></div>
<div class="space">
<div style="height: 150px"></div>
<div id="target"></div>
</div>
<div class="space"></div>
</div>
<script type="text/javascript">
// Transforms are ignored, but relative and absolute positioning are accounted
// for, so the ranges follow the offset position of the subject, not its static
// position.
//
// STATIC_POSITION = scroll distance to second spacer (550px)
// + position of the subject within it (150px)
const STATIC_POSITION = 700;
const RELATIVE_OFFSET = 300;
const USED_POSITION = STATIC_POSITION + RELATIVE_OFFSET;
const TARGET_HEIGHT = 100;
const VIEWPORT_HEIGHT = 500;
// START = position of the subject's start edge when it coincides with the end
// edge of the scrollport
// END = position of the subject's end edge when it coincides with the start
// edge of the scrollport
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 subject, block axis.');
promise_test(async t => {
// top: -200px, so the used position is 500px and the ranges move the other
// way.
target.classList.add('shifted-back');
t.add_cleanup(() => {
target.classList.remove('shifted-back');
});
const shiftedStart = STATIC_POSITION - 200 - VIEWPORT_HEIGHT;
const shiftedEnd = STATIC_POSITION - 200 + TARGET_HEIGHT;
await runTimelineRangeTest(t, {
rangeStart: { rangeName: 'cover', offset: CSS.percent(0) },
rangeEnd: { rangeName: 'cover', offset: CSS.percent(100) },
startOffset: shiftedStart,
endOffset: shiftedEnd,
axis: 'block'
});
await runTimelineRangeTest(t, {
rangeStart: { rangeName: 'contain', offset: CSS.percent(0) },
rangeEnd: { rangeName: 'contain', offset: CSS.percent(100) },
startOffset: shiftedStart + TARGET_HEIGHT,
endOffset: shiftedEnd - TARGET_HEIGHT,
axis: 'block'
});
}, 'View timeline with a negatively offset relatively positioned subject.');
</script>
</body>
</html>