'use client'; import { useState, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { ArrowUp } from 'lucide-react'; import { useReducedMotion } from '@/hooks/use-reduced-motion'; export function BackToTop() { const [isVisible, setIsVisible] = useState(false); const shouldReduceMotion = useReducedMotion(); useEffect(() => { const handleScroll = () => { // 当滚动超过 500px 时显示按钮 setIsVisible(window.scrollY > 500); }; window.addEventListener('scroll', handleScroll, { passive: true }); return () => window.removeEventListener('scroll', handleScroll); }, []); const scrollToTop = () => { window.scrollTo({ top: 0, behavior: shouldReduceMotion ? 'auto' : 'smooth', }); }; return ( {isVisible && ( )} ); }