website-front/banquise-website/lib/hooks/useOceanDepthEffect.ts
Sacha VAUDEY 545b7f9d91
Some checks failed
Build / build-check (pull_request) Failing after 1m46s
archi cleaning
2025-09-13 18:51:09 +02:00

23 lines
657 B
TypeScript

import { useState, useEffect } from 'react';
export const useOceanDepthEffect = () => {
const [scrollDepth, setScrollDepth] = useState(0);
useEffect(() => {
const handleScroll = () => {
const scrollPosition = window.scrollY;
const documentHeight = document.documentElement.scrollHeight - window.innerHeight;
const scrollPercentage = Math.min(scrollPosition / documentHeight, 1);
setScrollDepth(scrollPercentage);
};
window.addEventListener('scroll', handleScroll);
handleScroll(); // Initial call
return () => window.removeEventListener('scroll', handleScroll);
}, []);
return scrollDepth;
};