From c950409e86e58b8884faf624e63890779a725217 Mon Sep 17 00:00:00 2001 From: dertyp7 Date: Sun, 14 Jan 2024 20:19:48 +0100 Subject: [PATCH] Refactor intersection observers in App component --- src/App.tsx | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 82d485c..51e4ef6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -29,7 +29,7 @@ export default function App() { return; } - const observer = new IntersectionObserver( + const observerHash = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { @@ -49,6 +49,16 @@ export default function App() { } prevHash.current = entry.target.id; window.location.hash = entry.target.id; + } + }); + }, + { threshold: 0.7 } + ); + + const observerAnimations = new IntersectionObserver( + (entries) => { + entries.forEach((entry) => { + if (entry.isIntersecting) { entry.target.classList.add("active"); Array.from(entry.target.children).forEach((child) => { @@ -63,23 +73,27 @@ export default function App() { } }); }, - { threshold: 0.2 } + { threshold: 0.1 } ); if (aboutRef.current) { - observer.observe(aboutRef.current); + observerHash.observe(aboutRef.current); + observerAnimations.observe(aboutRef.current); } if (skillsRef.current) { - observer.observe(skillsRef.current); + observerHash.observe(skillsRef.current); + observerAnimations.observe(skillsRef.current); } if (projectsRef.current) { - observer.observe(projectsRef.current); + observerHash.observe(projectsRef.current); + observerAnimations.observe(projectsRef.current); } return () => { - observer.disconnect(); + observerHash.disconnect(); + observerAnimations.disconnect(); }; }, []);