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.

This commit is contained in:
dertyp7
2024-01-14 17:35:20 +01:00
parent a773551f96
commit 0ef74dabfe
6 changed files with 85 additions and 5 deletions

View File

@@ -19,10 +19,21 @@ export default function App() {
entries.forEach((entry) => { entries.forEach((entry) => {
if (entry.isIntersecting) { if (entry.isIntersecting) {
window.location.hash = entry.target.id; 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) { if (aboutRef.current) {

View File

@@ -54,17 +54,17 @@ export default function Projects() {
name="Website" name="Website"
description="This website" description="This website"
link="https://github.com/DerTyp7?tab=repositories" link="https://github.com/DerTyp7?tab=repositories"
/>{" "} />
<Project <Project
name="Website" name="Website"
description="This website" description="This website"
link="https://github.com/DerTyp7?tab=repositories" link="https://github.com/DerTyp7?tab=repositories"
/>{" "} />
<Project <Project
name="Website" name="Website"
description="This website" description="This website"
link="https://github.com/DerTyp7?tab=repositories" link="https://github.com/DerTyp7?tab=repositories"
/>{" "} />
<Project <Project
name="Website" name="Website"
description="This website" description="This website"

View File

@@ -35,6 +35,23 @@
} }
} }
&.active {
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
animation-name: slideIn;
animation-duration: 650ms;
animation-fill-mode: forwards;
}
@media (max-width: 1150px) { @media (max-width: 1150px) {
padding: 5rem 2rem; padding: 5rem 2rem;
} }

View File

@@ -14,5 +14,22 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
// @keyframes slideIn {
// from {
// opacity: 0;
// transform: translateY(20px);
// }
// to {
// opacity: 1;
// transform: translateY(0);
// }
// }
// &.active {
// animation-name: slideIn;
// animation-duration: 1s;
// animation-fill-mode: forwards;
// }
} }
} }

View File

@@ -1,3 +1,12 @@
@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.projects { .projects {
padding: 0 2rem; padding: 0 2rem;
@@ -5,6 +14,12 @@
padding: 0 15rem; padding: 0 15rem;
} }
&.active {
.project {
animation: fadeIn 300ms ease-in-out forwards;
}
}
.grid { .grid {
padding: 1rem 0; padding: 1rem 0;
display: flex; display: flex;
@@ -24,6 +39,7 @@
cursor: pointer; cursor: pointer;
max-width: 500px; max-width: 500px;
min-width: 300px; min-width: 300px;
opacity: 0;
&:hover { &:hover {
border-color: var(--color-accent-background); border-color: var(--color-accent-background);

View File

@@ -1,9 +1,28 @@
@keyframes slideInFromLeft {
0% {
transform: translateX(-100%);
opacity: 0;
}
100% {
transform: translateX(0);
opacity: 1;
}
}
.skills { .skills {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
gap: 30px; gap: 30px;
&.active {
@media (min-width: 768px) {
.skill {
animation: slideInFromLeft 300ms ease-in-out forwards;
}
}
}
.grid { .grid {
display: grid; display: grid;
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);
@@ -12,6 +31,7 @@
.skill { .skill {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: center;
align-items: center; align-items: center;
background-color: var(--color-background-foreground); background-color: var(--color-background-foreground);
border-radius: 5px; border-radius: 5px;
@@ -25,7 +45,6 @@
// &:hover { // &:hover {
// border-color: var(--color-accent-background); // border-color: var(--color-accent-background);
// } // }
img { img {
width: 32px; width: 32px;
height: 32px; height: 32px;