25 lines
686 B
TypeScript
25 lines
686 B
TypeScript
// src/hooks/useScrollAnimation.ts
|
|
import { useState, useEffect } from "react";
|
|
|
|
const useScrollAnimation = () => {
|
|
const [isVisible, setIsVisible] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const handleScroll = () => {
|
|
const elements = document.querySelectorAll(".scroll-animate");
|
|
elements.forEach((el) => {
|
|
const rect = el.getBoundingClientRect();
|
|
if (rect.top <= window.innerHeight * 0.8) {
|
|
el.classList.add("animate");
|
|
}
|
|
});
|
|
};
|
|
|
|
window.addEventListener("scroll", handleScroll);
|
|
handleScroll(); // Initial check
|
|
return () => window.removeEventListener("scroll", handleScroll);
|
|
}, []);
|
|
|
|
return isVisible;
|
|
};
|