Skip to content

Commit 05a4a2e

Browse files
committed
smooth scrolling and navbar sink effects added
1 parent a686bb6 commit 05a4a2e

File tree

5 files changed

+79
-28
lines changed

5 files changed

+79
-28
lines changed

frontend/package-lock.json

Lines changed: 35 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dependencies": {
1616
"@radix-ui/react-dropdown-menu": "^2.1.15",
1717
"@splinetool/react-spline": "^2.2.6",
18+
"@studio-freight/lenis": "^1.0.42",
1819
"@types/node": "20.5.9",
1920
"@types/react": "18.2.21",
2021
"@types/react-dom": "18.2.7",
@@ -23,7 +24,7 @@
2324
"clsx": "^2.1.1",
2425
"eslint-config-next": "13.4.19",
2526
"framer-motion": "^11.2.13",
26-
"lucide-react": "^0.511.0",
27+
"lenis": "^1.3.4",
2728
"next": "13.4.12",
2829
"next-emoji-rain": "^1.0.2",
2930
"postcss": "8.4.29",

frontend/src/components/Navbar.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,33 @@ import Terminal from './Terminal';
66

77
const Navbar = () => {
88
const [path, setPath] = useState<string[]>([]);
9+
const [isScrolled, setIsScrolled] = useState(false);
10+
911
useEffect(() => {
1012
const pathSegments: string[] | undefined = window.location.pathname.split('/').filter(segment => segment);
1113
if (pathSegments === undefined) setPath([]);
1214
else setPath(pathSegments.map(segment => segment.toUpperCase()));
1315
}, []);
1416

17+
useEffect(() => {
18+
const handleScroll = () => {
19+
setIsScrolled(window.scrollY > 0);
20+
};
21+
22+
window.addEventListener('scroll', handleScroll);
23+
return () =>window.removeEventListener('scroll', handleScroll);
24+
}, []);
25+
1526
return (
16-
<nav className="sticky top-0 flex justify-between items-center relative z-10 shadow-lg rounded-md bg-black/15 backdrop-blur-md xl:px-24 md:px-10 px-5 py-6">
17-
<div>
18-
<Link href="/">
19-
<Image
20-
src="/assets/csesoc_logo.svg"
21-
alt="CSESoc Logo"
22-
width={200}
23-
height={200}
24-
draggable={false}
25-
/>
26-
</Link>
27+
<nav className={`sticky top-0 flex justify-between items-center relative z-10 rounded-md bg-black/15 backdrop-blur-md xl:px-24 md:px-10 px-5 py-6 duration-500 ${isScrolled ? 'shadow-xl' : 'shadow-none'}`}>
28+
<Link href="/">
29+
<Image
30+
src="/assets/csesoc_logo.svg"
31+
alt="CSESoc Logo"
32+
width={200}
33+
height={200}
34+
draggable={false}
35+
/>
2736
<p className="font-mono mt-3 font-bold">
2837
<span className="text-green-500">csesoc@unsw</span>
2938
<span>:</span>
@@ -32,7 +41,7 @@ const Navbar = () => {
3241
{/* The interactive terminal that allows changing pages using 'cd' */}
3342
<Terminal/>
3443
</p>
35-
</div>
44+
</Link>
3645
<div>
3746
<div className="md:flex xl:gap-18 lg:gap-10 md:gap-5 text-right font-bold hidden">
3847
<Link href="/about">
@@ -60,7 +69,7 @@ const Navbar = () => {
6069
/>
6170
</a>
6271
</div>
63-
<div className="md:hidden xl:hidden lg:hidden text-right font-bold block">
72+
<div className="sm:hidden xl:hidden lg:hidden text-right font-bold block">
6473
<Hamburger />
6574
</div>
6675
</div>

frontend/src/pages/_app.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@ import '@/styles/globals.css';
22
import type { AppProps } from 'next/app';
33
import 'next-emoji-rain/dist/index.css';
44

5+
import Lenis from '@studio-freight/lenis';
6+
import { useEffect } from 'react';
7+
58
export default function App({ Component, pageProps }: AppProps) {
9+
10+
// Basic lenis setup
11+
// Basically updates on every frame to stay synchronised with browser refresh rate
12+
useEffect(() => {
13+
const lenis = new Lenis();
14+
15+
function raf(time : number) {
16+
lenis.raf(time);
17+
requestAnimationFrame(raf);
18+
}
19+
20+
requestAnimationFrame(raf);
21+
22+
return () => lenis.destroy();
23+
}, []);
24+
625
return <Component {...pageProps} />;
726
}

frontend/src/styles/globals.css

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
@tailwind components;
33
@tailwind utilities;
44

5-
html, body {
6-
scroll-behavior: smooth;
7-
}
8-
95
body {
106
color: white;
117
background: #000031;
128
font-family: 'Raleway', sans-serif;
9+
1310
}
1411

1512
@keyframes blink {

0 commit comments

Comments
 (0)