Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fade in animation to all section #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions suchith-m/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Footer from "./components/Footer";
import Home from "./components/Home";
import Sidebar from "./components/Sidebar";
import Skills from "./components/Skills";
import FadeInSection from "./components/FadeInSection";

function App() {
return (
Expand Down Expand Up @@ -33,18 +34,26 @@ function App() {
<Home />
</div>
</div>
<div className="relative">
<AboutMe />
</div>
<div className="relative">
<Experience />
</div>
<div className="relative">
<Skills />
</div>
<div className="relative">
<Contact />
</div>
<FadeInSection>
<div className="relative">
<AboutMe />
</div>
</FadeInSection>
<FadeInSection>
<div className="relative">
<Experience />
</div>
</FadeInSection>
<FadeInSection>
<div className="relative">
<Skills />
</div>
</FadeInSection>
<FadeInSection>
<div className="relative">
<Contact />
</div>
</FadeInSection>
<div className="relative">
<Footer />
</div>
Expand Down
23 changes: 23 additions & 0 deletions suchith-m/src/components/FadeInSection.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useEffect, useRef, useState } from "react";

function FadeInSection(props) {
const [isVisible, setVisible] = useState(true);
const domRef = useRef();
useEffect(() => {
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => setVisible(entry.isIntersecting));
});
observer.observe(domRef.current);
return () => observer.unobserve(domRef.current);
}, []);
return (
<div
className={`fade-in-section ${isVisible ? "animate-fade" : ""}`}
ref={domRef}
>
{props.children}
</div>
);
}

export default FadeInSection;