Skip to content

Commit

Permalink
Create progress.js
Browse files Browse the repository at this point in the history
  • Loading branch information
MastanSayyad committed Jun 25, 2024
1 parent f1dc660 commit 93d4e40
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions website3.0/src/app/ProgressBar/progress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use client';

import React, { useState, useEffect } from 'react';
import { usePathname } from 'next/navigation';

const ScrollProgressBar = () => {
const [scroll, setScroll] = useState(0);
const pathname = usePathname(); // Use usePathname to get the current path

const handleScroll = () => {
const scrolled = document.documentElement.scrollTop;
const totalScroll = document.documentElement.scrollHeight - document.documentElement.clientHeight;
const scrolledPercentage = `${(scrolled / totalScroll) * 100}%`;
setScroll(scrolledPercentage);
};

useEffect(() => {
window.addEventListener('scroll', handleScroll);
return () => window.removeEventListener('scroll', handleScroll);
}, []);

useEffect(() => {
setScroll(0); // Reset scroll progress on path change
}, [pathname]);

return (
<div className="scroll-progress-container">
<div className="scroll-progress-bar" style={{ width: scroll }} />
</div>
);
};

export default ScrollProgressBar;

0 comments on commit 93d4e40

Please sign in to comment.