mirror of
https://github.com/DerTyp7/dertyp7.github.io.git
synced 2025-10-29 12:52:08 +01:00
Refactor intersection observers in App component
This commit is contained in:
26
src/App.tsx
26
src/App.tsx
@@ -29,7 +29,7 @@ export default function App() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const observer = new IntersectionObserver(
|
const observerHash = new IntersectionObserver(
|
||||||
(entries) => {
|
(entries) => {
|
||||||
entries.forEach((entry) => {
|
entries.forEach((entry) => {
|
||||||
if (entry.isIntersecting) {
|
if (entry.isIntersecting) {
|
||||||
@@ -49,6 +49,16 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
prevHash.current = entry.target.id;
|
prevHash.current = entry.target.id;
|
||||||
window.location.hash = 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");
|
entry.target.classList.add("active");
|
||||||
|
|
||||||
Array.from(entry.target.children).forEach((child) => {
|
Array.from(entry.target.children).forEach((child) => {
|
||||||
@@ -63,23 +73,27 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
{ threshold: 0.2 }
|
{ threshold: 0.1 }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (aboutRef.current) {
|
if (aboutRef.current) {
|
||||||
observer.observe(aboutRef.current);
|
observerHash.observe(aboutRef.current);
|
||||||
|
observerAnimations.observe(aboutRef.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skillsRef.current) {
|
if (skillsRef.current) {
|
||||||
observer.observe(skillsRef.current);
|
observerHash.observe(skillsRef.current);
|
||||||
|
observerAnimations.observe(skillsRef.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (projectsRef.current) {
|
if (projectsRef.current) {
|
||||||
observer.observe(projectsRef.current);
|
observerHash.observe(projectsRef.current);
|
||||||
|
observerAnimations.observe(projectsRef.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
observer.disconnect();
|
observerHash.disconnect();
|
||||||
|
observerAnimations.disconnect();
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user