Skip to content

Commit

Permalink
Update timeline and animations when children of source element are re…
Browse files Browse the repository at this point in the history
…sized
  • Loading branch information
johannesodland committed Jan 25, 2024
1 parent 028fc68 commit 1fba765
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/scroll-timeline-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ function updateMeasurements(source) {
}

function updateSource(timeline, source) {
const oldSource = scrollTimelineOptions.get(timeline).source;
const timelineDetails = scrollTimelineOptions.get(timeline);
const oldSource = timelineDetails.source;
if (oldSource == source)
return;

Expand All @@ -272,7 +273,7 @@ function updateSource(timeline, source) {
}
}
}
scrollTimelineOptions.get(timeline).source = source;
timelineDetails.source = source;
if (source) {
let details = sourceDetails.get(source);
if (!details) {
Expand All @@ -287,10 +288,13 @@ function updateSource(timeline, source) {
// Use resize observer to detect changes to source size
const resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
updateMeasurements(entry.target)
updateMeasurements(timelineDetails.source)
}
});
resizeObserver.observe(source);
for (const child of source.children) {
resizeObserver.observe(child)
}

// Use mutation observer to detect updated style attributes on source element
const mutationObserver = new MutationObserver((records) => {
Expand Down
4 changes: 2 additions & 2 deletions test/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,6 @@ PASS /scroll-animations/view-timelines/view-timeline-source.tentative.html View
PASS /scroll-animations/view-timelines/view-timeline-source.tentative.html View timeline source is null when display:none
FAIL /scroll-animations/view-timelines/view-timeline-sticky-block.html View timeline with sticky target, block axis.
FAIL /scroll-animations/view-timelines/view-timeline-sticky-inline.html View timeline with sticky target, block axis.
FAIL /scroll-animations/view-timelines/view-timeline-subject-size-changes.html View timeline with subject size change after the creation of the animation
PASS /scroll-animations/view-timelines/view-timeline-subject-size-changes.html View timeline with subject size change after the creation of the animation
FAIL /scroll-animations/view-timelines/zero-intrinsic-iteration-duration.tentative.html Intrinsic iteration duration is non-negative
Passed 434 of 959 tests.
Passed 436 of 960 tests.

0 comments on commit 1fba765

Please sign in to comment.