Skip to content

Commit 96de108

Browse files
committed
correction when downscrolling
1 parent 7f4e092 commit 96de108

1 file changed

Lines changed: 75 additions & 18 deletions

File tree

website/index.html

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -373,34 +373,28 @@ <h2>Project Gamma</h2>
373373

374374
(function () {
375375
let lastMove = 0;
376+
let touchStartY = null;
376377

377-
document.addEventListener("wheel", function (event) {
378-
const target = event.target;
379-
380-
if (
381-
target.closest("select, option, button, input, textarea, a, .geo-popup-overlay")
382-
) {
383-
return;
384-
}
385-
378+
function shouldForceScroll(target) {
386379
const activeSection = document.querySelector(".fp-section.active");
387380
const activeSlide = activeSection?.querySelector(".fp-slide.active");
388-
389-
const sectionAnchor = activeSection?.dataset.anchor;
390381
const slideAnchor = activeSlide?.dataset.anchor;
391382

392-
const shouldForceScroll =
383+
return (
384+
slideAnchor === "bodytype-viz" ||
393385
slideAnchor === "body-types-viz" ||
394386
slideAnchor === "geopolitics-viz" ||
395387
slideAnchor === "fair-viz" ||
396388
target.closest("#bodytype-viz") ||
397389
target.closest("#geopolitics-map-viz") ||
398-
target.closest("#fair-viz");
399-
400-
if (!shouldForceScroll || !window.fullpage_api) return;
390+
target.closest("#geo-event-list") ||
391+
target.closest("#fair-viz")
392+
);
393+
}
401394

402-
const delta = event.deltaY;
403-
if (Math.abs(delta) < 10) return;
395+
function moveFullpage(deltaY, event) {
396+
if (!window.fullpage_api) return;
397+
if (Math.abs(deltaY) < 10) return;
404398

405399
const now = Date.now();
406400
if (now - lastMove < 750) {
@@ -411,11 +405,74 @@ <h2>Project Gamma</h2>
411405
event.preventDefault();
412406
lastMove = now;
413407

414-
if (delta > 0) {
408+
if (deltaY > 0) {
409+
window.fullpage_api.moveSectionDown();
410+
} else {
411+
window.fullpage_api.moveSectionUp();
412+
}
413+
}
414+
415+
document.addEventListener("wheel", function (event) {
416+
const target = event.target;
417+
418+
if (target.closest("select, option, button, input, textarea, a, .geo-popup-overlay")) {
419+
return;
420+
}
421+
422+
if (!shouldForceScroll(target)) return;
423+
424+
moveFullpage(event.deltaY, event);
425+
}, { passive: false, capture: true });
426+
427+
document.addEventListener("keydown", function (event) {
428+
if (!["ArrowDown", "PageDown", "ArrowUp", "PageUp"].includes(event.key)) return;
429+
430+
const target = event.target;
431+
if (target.closest("input, textarea, a, .geo-popup-overlay")) return;
432+
433+
document.querySelectorAll("select").forEach(select => {
434+
select.addEventListener("change", () => select.blur());
435+
});
436+
437+
const activeSection = document.querySelector(".fp-section.active");
438+
const activeSlide = activeSection?.querySelector(".fp-slide.active");
439+
const slideAnchor = activeSlide?.dataset.anchor;
440+
441+
const shouldForceScroll =
442+
slideAnchor === "bodytype-viz" ||
443+
slideAnchor === "body-types-viz" ||
444+
slideAnchor === "geopolitics-viz" ||
445+
slideAnchor === "fair-viz" ||
446+
slideAnchor === "never-medaled";
447+
448+
if (!shouldForceScroll || !window.fullpage_api) return;
449+
450+
event.preventDefault();
451+
452+
if (event.key === "ArrowDown" || event.key === "PageDown") {
415453
window.fullpage_api.moveSectionDown();
416454
} else {
417455
window.fullpage_api.moveSectionUp();
418456
}
457+
}, { capture: true });
458+
459+
document.addEventListener("touchstart", function (event) {
460+
touchStartY = event.touches[0].clientY;
461+
}, { passive: true, capture: true });
462+
463+
document.addEventListener("touchmove", function (event) {
464+
const target = event.target;
465+
466+
if (target.closest("select, option, button, input, textarea, a, .geo-popup-overlay")) {
467+
return;
468+
}
469+
470+
if (!shouldForceScroll(target) || touchStartY === null) return;
471+
472+
const currentY = event.touches[0].clientY;
473+
const deltaY = touchStartY - currentY;
474+
475+
moveFullpage(deltaY, event);
419476
}, { passive: false, capture: true });
420477
})();
421478
</script>

0 commit comments

Comments
 (0)