-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make navbar sticky with conditional styling enhancements (#442)
* Maked navbar sticky * Some Changes * Update App.jsx * Fixes issues --------- Co-authored-by: Alfiya Siddique <86224794+AlfiyaSiddique@users.noreply.github.com>
- Loading branch information
1 parent
156032d
commit c71813b
Showing
4 changed files
with
106 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
const ScrollProgressBar = () => { | ||
const [scrollPercentage, setScrollPercentage] = useState(0); | ||
|
||
useEffect(() => { | ||
const handleScroll = () => { | ||
const scrollTop = window.scrollY; // How much user has scrolled | ||
const windowHeight = window.innerHeight; // Height of the viewport | ||
const docHeight = document.documentElement.scrollHeight; // Height of the document | ||
|
||
const totalDocScrollLength = docHeight - windowHeight; | ||
const scrollPosition = (scrollTop / totalDocScrollLength) * 100; | ||
|
||
setScrollPercentage(scrollPosition); | ||
}; | ||
|
||
window.addEventListener("scroll", handleScroll); | ||
|
||
return () => window.removeEventListener("scroll", handleScroll); | ||
}, []); | ||
|
||
return ( | ||
<div | ||
style={{ | ||
position: "fixed", | ||
top: 0, | ||
left: 0, | ||
width: `${scrollPercentage}%`, | ||
height: "5px", | ||
color:red, | ||
backgroundColor: "#ff4500", | ||
zIndex: 1000, | ||
transition: "width 0.25s ease-out", | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default ScrollProgressBar; |