Skip to content

Commit a52637f

Browse files
committed
made blue background appear at different places depending on screen width
1 parent a50088f commit a52637f

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

apps/site/src/components/NavBar/NavBar.module.scss

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
position: fixed;
1515
text-align: right;
1616
backdrop-filter: blur(7px);
17+
transition: background-color 0.2s ease;
1718
}
1819

1920
.navbar {
@@ -63,11 +64,9 @@
6364
}
6465

6566
.bg-transparent {
66-
background-color: transparent !important;
67-
transition: background-color 0.3s ease;
68-
}
67+
background-color: transparent;
68+
}
6969

7070
.bg-ocean {
71-
background-color: rgba(1, 167, 197, 0.5) !important;
72-
transition: background-color 0.3s ease;
73-
}
71+
background-color: rgba(1, 167, 197, 0.5);
72+
}

apps/site/src/components/NavBar/NavBar.tsx

+17-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,26 @@ export default function NavBar() {
2020
const [hasScrolledToOcean, setHasScrolledToOcean] = useState(false);
2121

2222
useEffect(() => {
23+
const getScrollThreshold = () => {
24+
if (window.innerWidth < 768) {
25+
// For mobile screens
26+
return document.documentElement.scrollHeight / 5;
27+
} else if (window.innerWidth < 1200) {
28+
// For tablets and small desktops
29+
return document.documentElement.scrollHeight / 3.5;
30+
} else {
31+
// For large desktops
32+
return document.documentElement.scrollHeight / 2.55;
33+
}
34+
};
35+
36+
let scrollThreshold = getScrollThreshold();
2337
const handleScroll = () =>
24-
window.scrollY > document.documentElement.scrollHeight / 2.55 ? setHasScrolledToOcean(true) : setHasScrolledToOcean(false);
38+
window.scrollY > scrollThreshold ? setHasScrolledToOcean(true) : setHasScrolledToOcean(false);
2539

2640
window.addEventListener("scroll", handleScroll);
41+
42+
return () => window.removeEventListener("scroll", handleScroll);
2743
}, []);
2844

2945
return (

0 commit comments

Comments
 (0)