Skip to content

Commit 956aba2

Browse files
committed
conditionally show back to top button
1 parent 14198bd commit 956aba2

3 files changed

Lines changed: 44 additions & 23 deletions

File tree

src/App.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,45 @@ import { GetInTouch } from "./components/GetInTouch";
44
import { Technologies } from "./components/Technologies";
55
import Projects from "./components/Projects";
66
import Footer from "./components/Footer";
7+
import backTop from "../src/assets/back-top.svg";
8+
import { useEffect, useRef, useState } from "react";
79

810
export default function App() {
11+
const topRef = useRef<HTMLDivElement>(null);
12+
const [showButton, setShowButton] = useState(false);
13+
14+
useEffect(() => {
15+
const handleScroll = () => {
16+
setShowButton(window.scrollY > 300);
17+
};
18+
19+
window.addEventListener("scroll", handleScroll);
20+
return () => window.removeEventListener("scroll", handleScroll);
21+
}, []);
22+
23+
const scrollToTop = () => {
24+
topRef.current?.scrollIntoView({ behavior: "smooth" });
25+
};
926
return (
1027
<>
28+
<div ref={topRef} />
1129
<div className="flex flex-col mx-auto justify-items-end">
12-
<GetInTouch/>
30+
<GetInTouch />
1331
<Introduction />
1432
<AboutMe />
1533
<Technologies />
1634
<Projects />
1735
</div>
1836
<Footer />
37+
38+
{showButton && (
39+
<button
40+
onClick={scrollToTop}
41+
className="fixed z-50 px-4 py-4 transform -translate-x-1/2 bg-gray-200 rounded-full shadow-lg bottom-4 left-1/2"
42+
>
43+
<img src={backTop} alt="Back to Top" className="w-6 h-6" />
44+
</button>
45+
)}
1946
</>
2047
);
2148
}

src/assets/back-top.svg

Lines changed: 10 additions & 0 deletions
Loading

src/components/Technologies.tsx

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,26 @@ export const Technologies = () => {
1919
return (
2020
<div className="flex flex-col mx-5">
2121
<div>
22-
<motion.p
23-
whileInView={{ opacity: 1, y: 0 }}
24-
initial={{ opacity: 0, y: -100 }}
25-
transition={{ duration: 1.5 }}
26-
className="mt-20 mb-5 font-mono text-xl text-center"
27-
>
22+
<p className="mt-20 mb-5 font-mono text-xl text-center">
2823
<span className="text-2xl font-bold">Languages</span>
29-
</motion.p>
24+
</p>
3025
</div>
3126
<div className="flex flex-wrap justify-center gap-20">
3227
{languages.map((language) => (
33-
<motion.div
34-
whileInView={{ opacity: 1, x: 0 }}
35-
initial={{ opacity: 0, x: language.xLanguage }}
36-
transition={{ duration: 1.5 }}
37-
className="max-w-3xl text-center"
38-
key={language.id}
39-
>
28+
<div className="max-w-3xl text-center" key={language.id}>
4029
{" "}
4130
<img
4231
src={language.path}
4332
alt={language.name}
4433
className="w-20 h-20"
4534
/>
46-
</motion.div>
35+
</div>
4736
))}
4837
</div>
4938
<div>
50-
<motion.p
51-
whileInView={{ opacity: 1, x: 0 }}
52-
initial={{ opacity: 0, x: 100 }}
53-
transition={{ duration: 1.5 }}
54-
className="mt-20 mb-5 font-mono text-xl text-center"
55-
>
39+
<p className="mt-20 mb-5 font-mono text-xl text-center">
5640
<span className="text-2xl font-bold">Frameworks and Tools</span>
57-
</motion.p>
41+
</p>
5842
</div>
5943
<div className="flex flex-wrap justify-center gap-20">
6044
{tools.map((tool) => (

0 commit comments

Comments
 (0)