Skip to content

Commit 3934860

Browse files
authored
Website Update
1 parent 90f3bd7 commit 3934860

2 files changed

Lines changed: 83 additions & 30 deletions

File tree

docs/assets/js/shell.js

Lines changed: 82 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -634,20 +634,20 @@
634634

635635
function scrollToTarget(hash) {
636636
if (!hash || hash === "#") {
637-
return;
637+
return null;
638638
}
639639

640640
const target = document.querySelector(hash);
641641
if (!target) {
642-
return;
642+
return null;
643643
}
644644

645645
if (hash === '#hero'){
646646
window.scrollTo({
647647
top: 0,
648648
behavior: prefersReducedMotion ? "auto" : "smooth"
649649
});
650-
return;
650+
return 0;
651651
}
652652

653653
const destination = Math.max(0, target.getBoundingClientRect().top + window.scrollY - getNavOffset());
@@ -656,6 +656,8 @@
656656
top: destination,
657657
behavior: prefersReducedMotion ? "auto" : "smooth"
658658
});
659+
660+
return destination;
659661
}
660662

661663
function initAnchorScroll(){
@@ -670,7 +672,10 @@
670672
if (!target) return;
671673

672674
event.preventDefault();
673-
scrollToTarget(hash);
675+
const destination = scrollToTarget(hash);
676+
window.dispatchEvent(new CustomEvent('modelized:navautoscroll', {
677+
detail: { hash, destination }
678+
}));
674679

675680
const nav = document.querySelector('.nav');
676681
if (nav?.classList.contains('nav--open')){
@@ -792,25 +797,55 @@
792797
};
793798

794799
const homeSection = document.querySelector("#hero");
795-
let lastViewportHash = location.hash === "#hero" ? "" : location.hash;
796-
797-
const syncUrlToSection = (section) => {
798-
if (!section || !section.id) {
799-
return;
800+
let lockedHash = "";
801+
let lockedDestination = null;
802+
let lockFrame = 0;
803+
let lockTimer = 0;
804+
805+
const clearScrollLock = () => {
806+
if (lockFrame) {
807+
cancelAnimationFrame(lockFrame);
808+
lockFrame = 0;
800809
}
801-
802-
const sectionHash = `#${section.id}`;
803-
const nextHash = section === homeSection ? "" : sectionHash;
804-
if (nextHash === lastViewportHash) {
805-
return;
810+
if (lockTimer) {
811+
clearTimeout(lockTimer);
812+
lockTimer = 0;
806813
}
814+
lockedHash = "";
815+
lockedDestination = null;
816+
};
817+
818+
const releaseScrollLock = () => {
819+
clearScrollLock();
820+
syncFromViewport();
821+
};
822+
823+
const watchScrollLock = () => {
824+
if (!lockedHash) return;
825+
826+
let lastY = getScrollTop();
827+
let stillFrames = 0;
828+
829+
const tick = () => {
830+
lockFrame = 0;
831+
if (!lockedHash) return;
832+
833+
const currentY = getScrollTop();
834+
const delta = Math.abs(currentY - lastY);
835+
const nearDestination = lockedDestination !== null && Math.abs(currentY - lockedDestination) <= 2;
807836

808-
const nextUrl = nextHash
809-
? `${location.pathname}${location.search}${nextHash}`
810-
: `${location.pathname}${location.search}`;
837+
lastY = currentY;
838+
stillFrames = (nearDestination || delta < 0.5) ? (stillFrames + 1) : 0;
811839

812-
history.replaceState(null, "", nextUrl);
813-
lastViewportHash = nextHash;
840+
if (stillFrames >= 3) {
841+
releaseScrollLock();
842+
return;
843+
}
844+
845+
lockFrame = requestAnimationFrame(tick);
846+
};
847+
848+
lockFrame = requestAnimationFrame(tick);
814849
};
815850

816851
setActiveByHash(location.hash);
@@ -823,6 +858,11 @@
823858
map.forEach((_link, section) => sectionRatios.set(section, 0));
824859

825860
const syncFromViewport = () => {
861+
if (lockedHash) {
862+
setActiveByHash(lockedHash);
863+
return;
864+
}
865+
826866
const viewportFocus = window.innerHeight * 0.45;
827867
let currentSection = null;
828868
let bestScore = -Infinity;
@@ -853,7 +893,6 @@
853893

854894
const currentHash = currentSection.id ? `#${currentSection.id}` : "";
855895
setActiveByHash(currentHash);
856-
syncUrlToSection(currentSection);
857896
};
858897

859898
const observer = new IntersectionObserver(
@@ -872,6 +911,29 @@
872911

873912
map.forEach((_link, section) => observer.observe(section));
874913
requestAnimationFrame(syncFromViewport);
914+
915+
window.addEventListener('modelized:navautoscroll', (event) => {
916+
const nextHash = event.detail?.hash;
917+
if (!nextHash) return;
918+
919+
clearScrollLock();
920+
lockedHash = nextHash;
921+
lockedDestination = typeof event.detail?.destination === 'number' ? event.detail.destination : null;
922+
setActiveByHash(lockedHash);
923+
924+
if (prefersReducedMotion) {
925+
lockTimer = window.setTimeout(releaseScrollLock, 0);
926+
return;
927+
}
928+
929+
lockTimer = window.setTimeout(watchScrollLock, 120);
930+
});
931+
932+
window.addEventListener('orientationchange', clearScrollLock);
933+
window.addEventListener('resize', () => {
934+
if (!lockedHash) return;
935+
lockTimer = window.setTimeout(releaseScrollLock, 0);
936+
});
875937
}
876938

877939
function initSectionDepth() {
@@ -1211,15 +1273,6 @@
12111273
initParallax();
12121274
initHoverTracking();
12131275

1214-
if (location.hash){
1215-
requestAnimationFrame(() => {
1216-
scrollToTarget(location.hash);
1217-
});
1218-
}else{
1219-
requestAnimationFrame(() => {
1220-
window.scrollTo({ top: 0, behavior: 'auto' });
1221-
});
1222-
}
12231276
}
12241277

12251278
if (document.readyState === "loading") {

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=20260321i" defer></script>
136+
<script src="assets/js/shell.js?v=20260321j" defer></script>
137137
</body>
138138
</html>

0 commit comments

Comments
 (0)