Skip to content

Commit

Permalink
Restore iframe scroll position
Browse files Browse the repository at this point in the history
Restores iframe scroll position when `useIframeResizer` is `false` and the template has smooth scrolling enabled.

Fixes #14218

h/t @MoritzLost
  • Loading branch information
brianjhanson committed Apr 10, 2024
1 parent 6cefd4d commit 4c1729c
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/web/assets/cp/src/js/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,17 +695,10 @@ Craft.Preview = Garnish.Base.extend(
$iframe.on('load', () => {
this.iframeLoaded = true;
if (!resetScroll && sameHost) {
if (this.scrollTop !== null) {
$($iframe[0].contentWindow.document).scrollTop(
this.scrollTop
);
}

if (this.scrollLeft !== null) {
$($iframe[0].contentWindow.document).scrollLeft(
this.scrollLeft
);
}
$iframe[0].contentWindow.scrollTo(
this.scrollLeft || 0,
this.scrollTop || 0
);
}
});
}
Expand Down

0 comments on commit 4c1729c

Please sign in to comment.