This commit is contained in:
eric
2026-03-10 01:35:37 -05:00
parent ff51622bb6
commit be7a298604
69 changed files with 11016 additions and 57 deletions

View File

@@ -0,0 +1,43 @@
"use client";
/**
* 自实现滚动入场动画 - 封装待用
* 基于 IntersectionObserver,无第三方依赖
*/
import { useEffect, useRef, useState, type ReactNode } from "react";
type Props = {
children: ReactNode;
className?: string;
delay?: number;
};
export function CustomAnimateOnScroll({ children, className = "", delay = 0 }: Props) {
const ref = useRef<HTMLDivElement>(null);
const [visible, setVisible] = useState(false);
useEffect(() => {
const el = ref.current;
if (!el) return;
const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) setVisible(true);
},
{ threshold: 0.08, rootMargin: "0px 0px -40px 0px" }
);
observer.observe(el);
return () => observer.disconnect();
}, []);
return (
<div
ref={ref}
className={`animate-on-scroll ${visible ? "animate-on-scroll-visible" : ""} ${className}`}
style={{ transitionDelay: `${delay}ms` }}
>
{children}
</div>
);
}