Skip to content

Commit

Permalink
Explain setTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalabasa committed Feb 24, 2024
1 parent 0965c2e commit 1a1e82e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions htmz.dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
function htmz(frame) {
// Write your extensions here

// Remove setTimeout to let the browser autoscroll content changes into view
// The browser automatically scrolls DOM changes into view in response to user interaction.
// This delay prevents that, making this is the only case where we don't lean on browser defaults.
// Remove setTimeout wrapper to allow automatic scrolling.
setTimeout(() =>
document
.querySelector(frame.contentWindow.location.hash || null)
?.replaceWith(...frame.contentDocument.body.children)
);
}
</script>
<iframe hidden name=htmz onload="window.htmz(this)"></iframe>
<iframe hidden name="htmz" onload="window.htmz(this)"></iframe>

0 comments on commit 1a1e82e

Please sign in to comment.