Skip to content

Commit 5d2c156

Browse files
authored
Website Update
1 parent f4fbb3d commit 5d2c156

2 files changed

Lines changed: 46 additions & 6 deletions

File tree

docs/assets/js/shell.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@
347347
let lastPortrait = isPortraitMobile();
348348
let lastPortraitStableScrollY = lastPortrait ? getScrollTop() : 0;
349349
let pendingRecovery = null;
350+
let finishTimer = 0;
350351

351352
const updateStableState = () => {
352353
lastPortrait = isPortraitMobile();
@@ -355,19 +356,48 @@
355356
}
356357
};
357358

359+
const clearFinishTimer = () => {
360+
if (!finishTimer) return;
361+
window.clearTimeout(finishTimer);
362+
finishTimer = 0;
363+
};
364+
365+
const queueFinishRecovery = () => {
366+
if (!pendingRecovery?.restorePortraitScroll) return;
367+
clearFinishTimer();
368+
finishTimer = window.setTimeout(() => {
369+
pendingRecovery = null;
370+
updateStableState();
371+
}, 220);
372+
};
373+
358374
const settledRecovery = createSettledScheduler(() => {
359375
if (pendingRecovery?.restorePortraitScroll && isPortraitMobile()){
360376
const currentY = getScrollTop();
361-
if (Math.abs(currentY - lastPortraitStableScrollY) > 1){
362-
window.scrollTo({ top: lastPortraitStableScrollY, behavior: 'auto' });
377+
const targetY = pendingRecovery.scrollY;
378+
if (Math.abs(currentY - targetY) > 1){
379+
window.scrollTo({ top: targetY, behavior: 'auto' });
363380
}
381+
queueFinishRecovery();
382+
return;
364383
}
365384

366385
pendingRecovery = null;
367386
updateStableState();
368387
});
369388

370389
window.addEventListener('scroll', () => {
390+
if (pendingRecovery?.restorePortraitScroll && isPortraitMobile()){
391+
const currentY = getScrollTop();
392+
if (Math.abs(currentY - pendingRecovery.scrollY) > 1){
393+
clearFinishTimer();
394+
settledRecovery.schedule(80);
395+
} else {
396+
queueFinishRecovery();
397+
}
398+
return;
399+
}
400+
371401
if (!pendingRecovery && isPortraitMobile()){
372402
lastPortraitStableScrollY = getScrollTop();
373403
}
@@ -380,24 +410,34 @@
380410
}
381411

382412
pendingRecovery = {
383-
restorePortraitScroll: !wasPortrait
413+
restorePortraitScroll: !wasPortrait,
414+
scrollY: lastPortraitStableScrollY
384415
};
385-
settledRecovery.schedule(160);
416+
clearFinishTimer();
417+
if (pendingRecovery.restorePortraitScroll){
418+
settledRecovery.schedule(160);
419+
}
386420
});
387421

388422
window.addEventListener('resize', () => {
389423
if (pendingRecovery){
424+
clearFinishTimer();
390425
settledRecovery.schedule(120);
391426
return;
392427
}
393428
updateStableState();
394429
});
395430

396-
window.addEventListener('pageshow', updateStableState);
431+
window.addEventListener('pageshow', () => {
432+
pendingRecovery = null;
433+
clearFinishTimer();
434+
updateStableState();
435+
});
397436

398437
if (window.visualViewport){
399438
const syncViewportRecovery = () => {
400439
if (!pendingRecovery) return;
440+
clearFinishTimer();
401441
settledRecovery.schedule(120);
402442
};
403443

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,6 @@ <h2>Live Modules</h2>
133133

134134
<div id="footer-slot"></div>
135135

136-
<script src="assets/js/shell.js?v=20260321k" defer></script>
136+
<script src="assets/js/shell.js?v=20260321l" defer></script>
137137
</body>
138138
</html>

0 commit comments

Comments
 (0)