From e8a47f8a9c5e3d534f3a45f34d930181174c14c0 Mon Sep 17 00:00:00 2001 From: Johannes Odland Date: Sun, 7 Jan 2024 13:57:14 +0100 Subject: [PATCH] Fix current time for inactive timeline --- src/proxy-animation.js | 12 ++++++++++-- src/scroll-timeline-base.js | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/proxy-animation.js b/src/proxy-animation.js index a6aac12..c072619 100644 --- a/src/proxy-animation.js +++ b/src/proxy-animation.js @@ -888,7 +888,11 @@ function autoAlignStartTime(details) { // 5. Let start offset be the resolved timeline time corresponding to the start of the animation attachment range. // In the case of view timelines, it requires a calculation based on the proportion of the cover range. try { - startOffset = CSS.percent(fractionalStartDelay(details) * 100); + const startDelayFraction = fractionalStartDelay(details); + if (startDelayFraction === null) + return; + + startOffset = CSS.percent(startDelayFraction * 100); } catch { // TODO: Validate supported values for range start, to avoid exceptions when resolving the values. @@ -901,7 +905,11 @@ function autoAlignStartTime(details) { // 6. Let end offset be the resolved timeline time corresponding to the end of the animation attachment range. // In the case of view timelines, it requires a calculation based on the proportion of the cover range. try { - endOffset = CSS.percent((1 - fractionalEndDelay(details)) * 100); + const endDelayFraction = fractionalEndDelay(details); + if (endDelayFraction === null) + return; + + endOffset = CSS.percent((1 - endDelayFraction) * 100); } catch { // TODO: Validate supported values for range end, to avoid exceptions when resolving the values. diff --git a/src/scroll-timeline-base.js b/src/scroll-timeline-base.js index 195d1b8..11c9afe 100644 --- a/src/scroll-timeline-base.js +++ b/src/scroll-timeline-base.js @@ -611,6 +611,9 @@ export function range(timeline, phase) { if (!(timeline instanceof ViewTimeline)) return unresolved; + if (!sourceMeasurements || !subjectMeasurements) + return unresolved; + return calculateRange(phase, sourceMeasurements, subjectMeasurements, details.axis, details.inset); } @@ -810,7 +813,7 @@ export function fractionalOffset(timeline, value) { export function calculateRelativePosition(phaseRange, offset, coverRange, subject) { if (!phaseRange || !coverRange) - return 0; + return null; let style = getComputedStyle(subject) const info = {