Skip to content

Commit ae8959e

Browse files
committed
UX changes: scrolling animation when navigating using navbar
1 parent 7d39c5a commit ae8959e

1 file changed

Lines changed: 35 additions & 26 deletions

File tree

client/src/pages/index.tsx

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,67 @@
1-
import { Home, Info, LogIn, Mail,Star, Workflow } from "lucide-react";
1+
import { Home, Info, LogIn, Mail, Star, Workflow } from "lucide-react";
22
import React from "react";
33

4+
// literally just for UX, clicking on any navbar buttons will scroll to that section instead of jumping instantly to that section
5+
const scrollTo = (id: string) => {
6+
// question mark makes function scrolls only if the id is valid (wihout it an invalid id will error react)
7+
document.getElementById(id)?.scrollIntoView({
8+
behavior: "smooth",
9+
block: "start",
10+
});
11+
};
12+
413
export default function AboutPage() {
514
return (
6-
<div className="min-h-screen bg-slate-100">
15+
<div className="min-h-screen scroll-smooth bg-slate-100">
716
<nav className="fixed bottom-6 left-1/2 z-50 -translate-x-1/2">
817
<div className="flex items-center gap-6 rounded-full bg-[#000912] px-8 py-4 text-sm shadow-lg">
9-
<a
10-
href="#welcome"
18+
<button
19+
onClick={() => scrollTo("welcome")}
1120
className="flex items-center gap-2 text-gray-300 hover:text-white"
1221
>
13-
<Home className="h-5 w-5" />
22+
<Home className="h-4 w-4" />
1423
Welcome
15-
</a>
24+
</button>
1625

17-
<a
18-
href="#about"
26+
<button
27+
onClick={() => scrollTo("about")}
1928
className="flex items-center gap-2 text-gray-300 hover:text-white"
2029
>
21-
<Info className="h-5 w-5" />
30+
<Info className="h-4 w-4" />
2231
About
23-
</a>
32+
</button>
2433

25-
<a
26-
href="#how"
34+
<button
35+
onClick={() => scrollTo("how")}
2736
className="flex items-center gap-2 text-gray-300 hover:text-white"
2837
>
29-
<Workflow className="h-5 w-5" />
38+
<Workflow className="h-4 w-4" />
3039
How It Works
31-
</a>
40+
</button>
3241

33-
<a
34-
href="#why"
42+
<button
43+
onClick={() => scrollTo("why")}
3544
className="flex items-center gap-2 text-gray-300 hover:text-white"
3645
>
37-
<Star className="h-5 w-5" />
46+
<Star className="h-4 w-4" />
3847
Why Us
39-
</a>
48+
</button>
4049

41-
<a
42-
href="#login"
50+
<button
51+
onClick={() => scrollTo("login")}
4352
className="flex items-center gap-2 text-gray-300 hover:text-white"
4453
>
45-
<LogIn className="h-5 w-5" />
54+
<LogIn className="h-4 w-4" />
4655
Get Started
47-
</a>
56+
</button>
4857

49-
<a
50-
href="#contact"
58+
<button
59+
onClick={() => scrollTo("contact")}
5160
className="flex items-center gap-2 text-gray-300 hover:text-white"
5261
>
53-
<Mail className="h-5 w-5" />
62+
<Mail className="h-4 w-4" />
5463
Contact
55-
</a>
64+
</button>
5665
</div>
5766
</nav>
5867

0 commit comments

Comments
 (0)