feat: add animate quote at about page
This commit is contained in:
parent
e605b2e975
commit
93eb451880
5 changed files with 167 additions and 1 deletions
32
app/about/(quote)/useIntersectionObserver.js
Normal file
32
app/about/(quote)/useIntersectionObserver.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// useIntersectionObserver.js
|
||||
import { useEffect, useState, useRef } from "react";
|
||||
|
||||
export function useIntersectionObserver() {
|
||||
const [isIntersecting, setIsIntersecting] = useState(false);
|
||||
const ref = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
const observer = new IntersectionObserver(
|
||||
([entry]) => {
|
||||
setIsIntersecting(entry.isIntersecting);
|
||||
},
|
||||
{
|
||||
root: null,
|
||||
rootMargin: "0px",
|
||||
threshold: 0.1,
|
||||
}
|
||||
);
|
||||
|
||||
if (ref.current) {
|
||||
observer.observe(ref.current);
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (ref.current) {
|
||||
observer.unobserve(ref.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
return [ref, isIntersecting];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue