1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
<!DOCTYPE html>
<title>The animation-timeline: scroll() notation</title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/rewrite#scroll-notation">
<link rel="help" src="https://github.com/w3c/csswg-drafts/issues/6674">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<script src="support/testcommon.js"></script>
<style>
@keyframes anim {
from { translate: 50px; }
to { translate: 150px; }
}
html {
min-height: 100vh;
/* This makes the max scrollable ragne be 100px in root element */
padding-bottom: 100px;
}
#container {
width: 300px;
height: 300px;
overflow: scroll;
}
#target {
width: 100px;
/* This makes the max scrollable ragne be 100px in the block direction */
height: 100px;
}
/* large block content */
.block-content {
block-size: 100%;
}
/* large inline content */
.inline-content {
inline-size: 100%;
block-size: 5px;
/* This makes the max scrollable ragne be 100px in the inline direction */
padding-inline-end: 100px;
}
</style>
<body>
<div id="log"></div>
<script>
"use strict";
setup(assert_implements_animation_timeline);
const root = document.scrollingElement;
const createTargetWithStuff = function(t, contentClass) {
let container = document.createElement('div');
container.id = 'container';
let target = document.createElement('div');
target.id = 'target';
let content = document.createElement('div');
content.className = contentClass;
// <div id='container'>
// <div id='target'></div>
// <div class=contentClass></div>
// </div>
document.body.appendChild(container);
container.appendChild(target);
container.appendChild(content);
if (t && typeof t.add_cleanup === 'function') {
t.add_cleanup(() => {
content.remove();
target.remove();
container.remove();
});
}
return [container, target];
};
async function scrollLeft(element, value) {
element.scrollLeft = value;
await waitForNextFrame();
}
async function scrollTop(element, value) {
element.scrollTop = value;
await waitForNextFrame();
}
promise_test(async t => {
let [container, div] = createTargetWithStuff(t, 'block-content');
await runAndWaitForFrameUpdate(() => {
div.style.animation = "anim 10s linear";
div.style.animationTimeline = "scroll(nearest)";
});
await scrollTop(root, 50);
assert_equals(getComputedStyle(div).translate, '50px');
await scrollTop(container, 50);
assert_equals(getComputedStyle(div).translate, '100px');
await scrollTop(root, 0);
}, 'animation-timeline: scroll(nearest)');
promise_test(async t => {
let [container, div] = createTargetWithStuff(t, 'block-content');
await runAndWaitForFrameUpdate(() => {
div.style.animation = "anim 10s linear";
div.style.animationTimeline = "scroll(root)";
});
await scrollTop(container, 50);
assert_equals(getComputedStyle(div).translate, '50px');
await scrollTop(root, 50);
assert_equals(getComputedStyle(div).translate, '100px');
await scrollTop(root, 0);
}, 'animation-timeline: scroll(root)');
promise_test(async t => {
let [container, div] = createTargetWithStuff(t, 'block-content');
await runAndWaitForFrameUpdate(() => {
container.style.animation = "anim 10s linear";
container.style.animationTimeline = "scroll(self)";
});
await scrollTop(container, 50);
assert_equals(getComputedStyle(container).translate, '100px');
}, 'animation-timeline: scroll(self)');
promise_test(async t => {
let [container, div] = createTargetWithStuff(t, 'block-content');
await runAndWaitForFrameUpdate(() => {
div.style.animation = "anim 10s linear";
div.style.animationTimeline = "scroll(self)";
});
await scrollTop(container, 50);
assert_equals(getComputedStyle(div).translate, 'none');
}, 'animation-timeline: scroll(self), on non-scroller');
promise_test(async t => {
let [container, div] = createTargetWithStuff(t, 'inline-content');
await runAndWaitForFrameUpdate(() => {
div.style.animation = "anim 10s linear";
div.style.animationTimeline = "scroll(inline)";
});
await scrollLeft(container, 50);
assert_equals(getComputedStyle(div).translate, '100px');
}, 'animation-timeline: scroll(inline)');
promise_test(async t => {
let [container, div] = createTargetWithStuff(t, 'block-content');
await runAndWaitForFrameUpdate(() => {
container.style.writingMode = 'vertical-lr';
div.style.animation = "anim 10s linear";
div.style.animationTimeline = "scroll(x)";
});
await scrollLeft(container, 50);
assert_equals(getComputedStyle(div).translate, '100px');
}, 'animation-timeline: scroll(x)');
promise_test(async t => {
let [container, div] = createTargetWithStuff(t, 'inline-content');
await runAndWaitForFrameUpdate(() => {
container.style.writingMode = 'vertical-lr';
div.style.animation = "anim 10s linear";
div.style.animationTimeline = "scroll(y)";
});
await scrollTop(container, 50);
assert_equals(getComputedStyle(div).translate, '100px');
}, 'animation-timeline: scroll(y)');
// TODO: Add more tests which change the overflow property of the container for
// scroll(nearest)
</script>
</body>
|