fix: make the reading viewport a script-driven scroll container so sticky and view timelines work
This commit is contained in:
@@ -99,8 +99,19 @@ const browserRuntime = (): NavigationRuntime => ({
|
||||
pushHash: (hash) => window.history.pushState(window.history.state, "", hash),
|
||||
replaceHash: (hash) =>
|
||||
window.history.replaceState(window.history.state, "", hash),
|
||||
scrollTarget: (target, behavior) =>
|
||||
target.scrollIntoView({ behavior, block: "start" }),
|
||||
scrollTarget: (target, behavior) => {
|
||||
// Inside the live reading stage the document is the only real scroller;
|
||||
// scrollIntoView would move the script-driven inner viewport instead.
|
||||
if (target.closest('[data-reading-stage="live"]') === null) {
|
||||
target.scrollIntoView({ behavior, block: "start" });
|
||||
return;
|
||||
}
|
||||
const margin = parseFloat(getComputedStyle(target).scrollMarginTop) || 0;
|
||||
window.scrollTo({
|
||||
top: window.scrollY + target.getBoundingClientRect().top - margin,
|
||||
behavior,
|
||||
});
|
||||
},
|
||||
focusHeading: (target) => {
|
||||
target
|
||||
.querySelector<HTMLElement>('h1[tabindex="-1"], h2[tabindex="-1"]')
|
||||
|
||||
Reference in New Issue
Block a user