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 4, 2024
1 parent ebe0be5 commit 858b288
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/scroll-timeline-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,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 @@ -267,7 +268,7 @@ function updateSource(timeline, source) {
}
}
}
scrollTimelineOptions.get(timeline).source = source;
timelineDetails.source = source;
if (source) {
let details = sourceDetails.get(source);
if (!details) {
Expand All @@ -282,10 +283,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

0 comments on commit 858b288

Please sign in to comment.