Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useAdaptiveBackgroundIntelligence from './hooks/useAdaptiveBackgroundInte
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';

import ScrollToTop from './components/ScrollToTop';
import ScrollProgressBar from './components/ScrollProgress';
import FloatingBottomBar from './components/FloatingBottomBar';
import BackToTopButton from './components/BackToTop';
import GlassyUILandingPage from './components/GlassyUILandingPage';
Expand Down Expand Up @@ -137,6 +138,7 @@ const App: React.FC = () => {
/>
<Router>
<ScrollToTop />
<ScrollProgressBar />
<Header />
<AiChatbot />
<BackToTopButton />
Expand Down
12 changes: 8 additions & 4 deletions src/components/ScrollProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const ScrollProgressBar: React.FC = () => {

useEffect(() => {
let animationFrameId: number;
const scrollElement = document.scrollingElement ?? document.documentElement;

const handleScroll = () => {
if (animationFrameId) {
Expand All @@ -14,19 +15,21 @@ const ScrollProgressBar: React.FC = () => {

animationFrameId = requestAnimationFrame(() => {
const totalHeight =
document.documentElement.scrollHeight - window.innerHeight;
const scrolled = totalHeight > 0 ? window.scrollY / totalHeight : 0;
scrollElement.scrollHeight - scrollElement.clientHeight;
const scrollTop = scrollElement.scrollTop;
const rawProgress = totalHeight > 0 ? scrollTop / totalHeight : 0;
const scrolled = Math.min(1, Math.max(0, rawProgress));
setScrollProgress(scrolled);
});
};

window.addEventListener('scroll', handleScroll, { passive: true });
scrollElement.addEventListener('scroll', handleScroll, { passive: true });

// Initial calculation in case the page is already scrolled on load
handleScroll();

return () => {
window.removeEventListener('scroll', handleScroll);
scrollElement.removeEventListener('scroll', handleScroll);
if (animationFrameId) {
cancelAnimationFrame(animationFrameId);
}
Expand All @@ -51,6 +54,7 @@ const ScrollProgressBar: React.FC = () => {
transition: 'transform 0.1s ease-out',
willChange: 'transform',
}}
aria-hidden='true'
/>
);
};
Expand Down