-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #378 from aslams2020/main
Added "Scroll Down Progress Bar" to The Website
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#progressBar { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 0%; | ||
height: 8px; | ||
background: linear-gradient(90deg, rgba(8, 106, 68, 1) 0%, rgba(8, 170, 106, 1) 50%, rgba(8, 106, 68, 1) 100%); | ||
z-index: 99; | ||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); | ||
/* transition: width 0.3s ease-in-out; */ | ||
} | ||
|
||
#progressBar:hover { | ||
background: linear-gradient(90deg, rgba(8, 170, 106, 1) 0%, rgba(8, 106, 68, 1) 100%); | ||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4); | ||
} |
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,24 @@ | ||
|
||
import React, { useEffect } from 'react'; | ||
import './ProgressBar.css'; | ||
|
||
const ProgressBar = () => { | ||
|
||
useEffect(() => { | ||
const handleScroll = () => { | ||
const winScroll = document.body.scrollTop || document.documentElement.scrollTop; | ||
const height = document.documentElement.scrollHeight - document.documentElement.clientHeight; | ||
const scrolled = (winScroll / height) * 100; | ||
document.getElementById('progressBar').style.width = scrolled + '%'; | ||
}; | ||
|
||
|
||
window.addEventListener('scroll', handleScroll); | ||
return () => window.removeEventListener('scroll', handleScroll); | ||
}, []); | ||
|
||
return <div id="progressBar"></div>; | ||
|
||
}; | ||
|
||
export default ProgressBar; |