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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
|
<!DOCTYPE html>
<title>The animation-timeline: scroll-timeline-name</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-timelines-named">
<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>
<script src="/scroll-animations/scroll-timelines/testcommon.js"></script>
<style>
@keyframes anim {
from { translate: 50px; }
to { translate: 150px; }
}
@keyframes anim-2 {
from { z-index: 0; }
to { z-index: 100; }
}
#target {
width: 100px;
height: 100px;
}
.square {
width: 100px;
height: 100px;
}
.square-container {
width: 300px;
height: 300px;
}
.scroller {
overflow: scroll;
}
.content {
inline-size: 100%;
block-size: 100%;
padding-inline-end: 100px;
padding-block-end: 100px;
}
</style>
<body>
<div id="log"></div>
<script>
"use strict";
setup(assert_implements_animation_timeline);
function createScroller(t, scrollerSizeClass) {
let scroller = document.createElement('div');
let className = scrollerSizeClass || 'square';
scroller.className = `scroller ${className}`;
let content = document.createElement('div');
content.className = 'content';
scroller.appendChild(content);
t.add_cleanup(function() {
content.remove();
scroller.remove();
});
return scroller;
}
function createTarget(t) {
let target = document.createElement('div');
target.id = 'target';
t.add_cleanup(function() {
target.remove();
});
return target;
}
function createScrollerAndTarget(t, scrollerSizeClass) {
return [createScroller(t, scrollerSizeClass), createTarget(t)];
}
async function waitForScrollTop(scroller, percentage) {
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
scroller.scrollTop = maxScroll * percentage / 100;
return waitForNextFrame();
}
async function waitForScrollLeft(scroller, percentage) {
const maxScroll = scroller.scrollWidth - scroller.clientWidth;
scroller.scrollLeft = maxScroll * percentage / 100;
return waitForNextFrame();
}
// -------------------------
// Test scroll-timeline-name
// -------------------------
promise_test(async t => {
let target = document.createElement('div');
target.id = 'target';
target.className = 'scroller';
let content = document.createElement('div');
content.className = 'content';
await runAndWaitForFrameUpdate(() => {
// <div id='target' class='scroller'>
// <div id='content'></div>
// </div>
document.body.appendChild(target);
target.appendChild(content);
target.style.scrollTimelineName = '--timeline';
target.style.animation = "anim 10s linear";
target.style.animationTimeline = '--timeline';
target.scrollTop = 50; // 50%
});
assert_equals(getComputedStyle(target).translate, '100px');
content.remove();
target.remove();
}, 'scroll-timeline-name is referenceable in animation-timeline on the ' +
'declaring element itself');
promise_test(async t => {
let [parent, target] = createScrollerAndTarget(t, 'square-container');
await runAndWaitForFrameUpdate(() => {
// <div id='parent' class='scroller'>
// <div id='target'></div>
// <div id='content'></div>
// </div>
document.body.appendChild(parent);
parent.insertBefore(target, parent.firstElementChild);
parent.style.scrollTimelineName = '--timeline';
target.style.animation = "anim 10s linear";
target.style.animationTimeline = '--timeline';
parent.scrollTop = 100; // 50%
});
assert_equals(getComputedStyle(target).translate, '100px');
}, "scroll-timeline-name is referenceable in animation-timeline on that " +
"element's descendants");
// See https://github.com/w3c/csswg-drafts/issues/7047
promise_test(async t => {
let [sibling, target] = createScrollerAndTarget(t);
await runAndWaitForFrameUpdate(() => {
// <div id='sibling' class='scroller'> ... </div>
// <div id='target'></div>
document.body.appendChild(sibling);
document.body.appendChild(target);
// Resolvable if using a deferred timeline, but otherwise can only resolve
// if an ancestor container of the target element.
sibling.style.scrollTimelineName = '--timeline';
target.style.animation = "anim 10s linear";
target.style.animationTimeline = '--timeline';
sibling.scrollTop = 50; // 50%
});
assert_equals(getComputedStyle(target).translate, '50px',
'Animation with unknown timeline name holds current time at zero');
}, "scroll-timeline-name is not referenceable in animation-timeline on that " +
"element's siblings");
promise_test(async t => {
let parent = document.createElement('div');
parent.className = 'square';
parent.style.overflowX = 'clip'; // This makes overflow-y be clip as well.
let target = document.createElement('div');
target.id = 'target';
await runAndWaitForFrameUpdate(() => {
// <div id='parent' style='overflow-x: clip'>...
// <div id='target'></div>
// </div>
document.body.appendChild(parent);
parent.appendChild(target);
parent.style.scrollTimelineName = '--timeline';
target.style.animation = "anim 10s linear";
target.style.animationTimeline = '--timeline';
});
assert_equals(getComputedStyle(target).translate, 'none',
'Animation with an unresolved current time');
target.remove();
parent.remove();
}, 'scroll-timeline-name on an element which is not a scroll-container');
promise_test(async t => {
let [scroller, target] = createScrollerAndTarget(t);
await runAndWaitForFrameUpdate(() => {
// <div id='scroller' class='scroller'> ...
// <div id='target'></div>
// </div>
document.body.appendChild(scroller);
scroller.appendChild(target);
scroller.style.scrollTimelineName = '--timeline-A';
scroller.scrollTop = 50; // 25%
target.style.animation = "anim 10s linear";
target.style.animationTimeline = '--timeline-B';
});
const anim = target.getAnimations()[0];
assert_true(!!anim, 'Failed to create animation');
assert_equals(anim.timeline, null);
// Hold time of animation is zero.
assert_equals(getComputedStyle(target).translate, '50px');
scroller.style.scrollTimelineName = '--timeline-B';
await waitForNextFrame();
assert_true(!!anim.timeline, 'Failed to create timeline');
assert_equals(getComputedStyle(target).translate, '75px');
}, 'Change in scroll-timeline-name to match animation timeline updates animation.');
promise_test(async t => {
let [scroller, target] = createScrollerAndTarget(t);
await runAndWaitForFrameUpdate(() => {
// <div id='scroller' class='scroller'> ...
// <div id='target'></div>
// </div>
document.body.appendChild(scroller);
scroller.appendChild(target);
scroller.style.scrollTimelineName = '--timeline-A';
scroller.scrollTop = 50; // 25%
target.style.animation = "anim 10s linear";
target.style.animationTimeline = '--timeline-A';
});
const anim = target.getAnimations()[0];
assert_true(!!anim, 'Failed to create animation');
assert_true(!!anim.timeline, 'Failed to create timeline');
assert_equals(getComputedStyle(target).translate, '75px');
assert_percents_equal(anim.startTime, 0);
assert_percents_equal(anim.currentTime, 25);
scroller.style.scrollTimelineName = '--timeline-B';
await waitForNextFrame();
// Switching to a null timeline pauses the animation.
assert_equals(anim.timeline, null, 'Failed to remove timeline');
assert_equals(getComputedStyle(target).translate, '75px');
assert_equals(anim.startTime, null);
assert_times_equal(anim.currentTime, 2500);
}, 'Change in scroll-timeline-name to no longer match animation timeline updates animation.');
promise_test(async t => {
let target = createTarget(t);
let scroller1 = createScroller(t);
let scroller2 = createScroller(t);
target.style.animation = 'anim 10s linear';
target.style.animationTimeline = '--timeline';
scroller1.style.scrollTimelineName = '--timeline';
scroller1.id = 'A';
scroller2.id = 'B';
await runAndWaitForFrameUpdate(() => {
// <div class='scroller' id='A'> ...
// <div class='scroller' id='B'> ...
// <div id='target'></div>
// </div>
// </div>
document.body.appendChild(scroller1);
scroller1.appendChild(scroller2);
scroller2.appendChild(target);
scroller1.style.scrollTimelineName = '--timeline';
scroller1.scrollTop = 50; // 25%
scroller2.scrollTop = 100; // 50%
});
const anim = target.getAnimations()[0];
assert_true(!!anim.timeline, 'Failed to retrieve animation');
assert_equals(anim.timeline.source.id, 'A');
assert_equals(getComputedStyle(target).translate, '75px');
scroller2.style.scrollTimelineName = '--timeline';
await waitForNextFrame();
// The timeline should be updated to scroller2.
assert_true(!!anim.timeline, 'Animation no longer has a timeline');
assert_equals(anim.timeline.source.id, 'B', 'Timeline not updated');
assert_equals(getComputedStyle(target).translate, '100px');
}, 'Timeline lookup updates candidate when closer match available.');
promise_test(async t => {
let wrapper = createScroller(t);
wrapper.classList.remove('scroller');
let target = createTarget(t);
await runAndWaitForFrameUpdate(() => {
// <div id='wrapper'> ...
// <div id='target'></div>
// </div>
document.body.appendChild(wrapper);
wrapper.appendChild(target);
target.style.animation = "anim 10s linear";
target.style.animationTimeline = '--timeline';
});
// Timeline initially cannot be resolved, resulting in a null
// timeline. The animation's hold time is zero.
// let anim = document.getAnimations()[0];
assert_equals(getComputedStyle(target).translate, '50px');
await runAndWaitForFrameUpdate(() => {
// <div id='wrapper' class="scroller"> ...
// <div id='target'></div>
// </div>
wrapper.classList.add('scroller');
wrapper.style.scrollTimelineName = '--timeline';
wrapper.scrollTop = 50; // 25%
});
// The timeline should be updated to scroller.
assert_equals(getComputedStyle(target).translate, '75px');
}, 'Timeline lookup updates candidate when match becomes available.');
// -------------------------
// Test scroll-timeline-axis
// -------------------------
promise_test(async t => {
let [scroller, target] = createScrollerAndTarget(t);
scroller.style.writingMode = 'vertical-lr';
await runAndWaitForFrameUpdate(() => {
// <div id='scroller' class='scroller'> ...
// <div id='target'></div>
// </div>
document.body.appendChild(scroller);
scroller.appendChild(target);
scroller.style.scrollTimeline = '--timeline block';
target.style.animation = "anim-2 10s linear";
target.style.animationTimeline = '--timeline';
});
await waitForScrollLeft(scroller, 50);
assert_equals(getComputedStyle(target).zIndex, '50');
}, 'scroll-timeline-axis is block');
promise_test(async t => {
let [scroller, target] = createScrollerAndTarget(t);
scroller.style.writingMode = 'vertical-lr';
await runAndWaitForFrameUpdate(() => {
// <div id='scroller' class='scroller'> ...
// <div id='target'></div>
// </div>
document.body.appendChild(scroller);
scroller.appendChild(target);
scroller.style.scrollTimeline = '--timeline inline';
target.style.animation = "anim-2 10s linear";
target.style.animationTimeline = '--timeline';
});
await waitForScrollTop(scroller, 50);
assert_equals(getComputedStyle(target).zIndex, '50');
}, 'scroll-timeline-axis is inline');
promise_test(async t => {
let [scroller, target] = createScrollerAndTarget(t);
scroller.style.writingMode = 'vertical-lr';
await runAndWaitForFrameUpdate(() => {
// <div id='scroller' class='scroller'> ...
// <div id='target'></div>
// </div>
document.body.appendChild(scroller);
scroller.appendChild(target);
scroller.style.scrollTimeline = '--timeline x';
target.style.animation = "anim-2 10s linear";
target.style.animationTimeline = '--timeline';
});
await waitForScrollLeft(scroller, 50);
assert_equals(getComputedStyle(target).zIndex, '50');
}, 'scroll-timeline-axis is x');
promise_test(async t => {
let [scroller, target] = createScrollerAndTarget(t);
scroller.style.writingMode = 'vertical-lr';
await runAndWaitForFrameUpdate(() => {
// <div id='scroller' class='scroller'> ...
// <div id='target'></div>
// </div>
document.body.appendChild(scroller);
scroller.appendChild(target);
scroller.style.scrollTimeline = '--timeline y';
target.style.animation = "anim-2 10s linear";
target.style.animationTimeline = '--timeline';
});
await waitForScrollTop(scroller, 50);
assert_equals(getComputedStyle(target).zIndex, '50');
}, 'scroll-timeline-axis is y');
promise_test(async t => {
let [scroller, target] = createScrollerAndTarget(t);
await runAndWaitForFrameUpdate(() => {
// <div id='scroller' class='scroller'> ...
// <div id='target'></div>
// </div>
document.body.appendChild(scroller);
scroller.appendChild(target);
scroller.style.scrollTimeline = '--timeline block';
target.style.animation = "anim-2 10s linear";
target.style.animationTimeline = '--timeline';
});
await waitForScrollTop(scroller, 25);
await waitForScrollLeft(scroller, 75);
assert_equals(getComputedStyle(target).zIndex, '25');
scroller.style.scrollTimelineAxis = 'inline';
await waitForNextFrame();
assert_equals(getComputedStyle(target).zIndex, '75');
}, 'scroll-timeline-axis is mutated');
</script>
</body>
|