From 0ef74dabfe7b2dea0d93db28de2d5109ebecf8e3 Mon Sep 17 00:00:00 2001 From: dertyp7 Date: Sun, 14 Jan 2024 17:35:20 +0100 Subject: [PATCH] Add active class to target and its children elements when intersecting, and remove active class when not intersecting. Adjust threshold for intersection observer. Add slideIn animation to elements with active class. --- src/App.tsx | 13 ++++++++++++- src/sections/Projects.tsx | 6 +++--- src/styles/About.scss | 17 +++++++++++++++++ src/styles/App.scss | 17 +++++++++++++++++ src/styles/Projects.scss | 16 ++++++++++++++++ src/styles/Skills.scss | 21 ++++++++++++++++++++- 6 files changed, 85 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index d0fc5f7..126fb46 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -19,10 +19,21 @@ export default function App() { entries.forEach((entry) => { if (entry.isIntersecting) { window.location.hash = entry.target.id; + entry.target.classList.add("active"); + + Array.from(entry.target.children).forEach((child) => { + child.classList.add("active"); + }); + } else { + entry.target.classList.remove("active"); + + Array.from(entry.target.children).forEach((child) => { + child.classList.remove("active"); + }); } }); }, - { threshold: 0.5 } + { threshold: 0.2 } ); if (aboutRef.current) { diff --git a/src/sections/Projects.tsx b/src/sections/Projects.tsx index 41a0ed3..368bc5f 100644 --- a/src/sections/Projects.tsx +++ b/src/sections/Projects.tsx @@ -54,17 +54,17 @@ export default function Projects() { name="Website" description="This website" link="https://github.com/DerTyp7?tab=repositories" - />{" "} + /> {" "} + /> {" "} + />