forked from rahulsainlll/git-trace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgressbar.tsx
52 lines (47 loc) · 1.32 KB
/
Progressbar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { useState, useEffect } from "react";
const ProgressBar = () => {
const [scrollProgress, setScrollProgress] = useState(0);
// Update progress bar on scroll
useEffect(() => {
const handleScroll = () => {
const totalHeight =
document.documentElement.scrollHeight - window.innerHeight;
const scrollPosition = window.pageYOffset;
const scrollPercentage = (scrollPosition / totalHeight) * 100;
setScrollProgress(scrollPercentage);
};
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
}, []);
return (
<>
<div
className="progress-bar-container"
style={{
position: "fixed",
top: "0",
left: "0",
width: "100%",
zIndex: "99999",
height: "7px",
}}
>
{/* Glowing Progress Bar */}
<div
className="progress-bar"
style={{
border: "none",
borderRadius: "2rem",
height: "100%",
width: `${scrollProgress}%`,
background: "linear-gradient(90deg, #ffff ,#404f78)",
boxShadow: "0 0 2px #ffff, 0 0 5px #404f78, 0 0 10px #2F80ED",
}}
></div>
</div>
</>
);
};
export default ProgressBar;