From 669f328c4bdef98b25e24907018b64289bb52983 Mon Sep 17 00:00:00 2001 From: Alvaro Date: Tue, 15 Oct 2024 16:07:53 +0200 Subject: [PATCH] Fix resizable and scroll --- src/components/section-2/index.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/section-2/index.tsx b/src/components/section-2/index.tsx index 2b90102..58c23b7 100644 --- a/src/components/section-2/index.tsx +++ b/src/components/section-2/index.tsx @@ -33,14 +33,23 @@ export default function Section2() { target: scrollSectionRef, }); const [globePhase, setGlobePhase] = useState(0); - const [resizableWidth, setResizableWidth] = useState(400); const screenWidth = useScreenWidthWithResize(); + const [resizableWidth, setResizableWidth] = useState(screenWidth ? screenWidth / 2 : 800); useEffect(() => { - scrollToSection(`globe-phase-${globePhase + 1}`); + if (globePhase) { + scrollToSection(`globe-phase-${globePhase + 1}`); + } }, [globePhase]); + useEffect(() => { + if (screenWidth || resizableWidth === 0) { + setResizableWidth(screenWidth / 2); + } + } + , [screenWidth]); + useMotionValueEvent(scrollYProgress, "change", (latest) => { if (latest >= 0 && latest < 0.1 && globePhase !== 0) { setGlobePhase(0);