diff --git a/frontend/src/pages/Matches.tsx b/frontend/src/pages/Matches.tsx index 07ebf99..98e0ffa 100644 --- a/frontend/src/pages/Matches.tsx +++ b/frontend/src/pages/Matches.tsx @@ -195,6 +195,16 @@ export default function Matches() { const [loading, setLoading] = useState(false) const [showAllUpcoming, setShowAllUpcoming] = useState(false) // 默认仅展示未来 3 天;true 展开全部 const [liveMatches, setLiveMatches] = useState([]) // 进行中比赛(顶部独立区块) + const [showBackTop, setShowBackTop] = useState(false) // 回到顶部按钮显示态 + + // 监听滚动,超过 300px 显示回到顶部按钮 + useEffect(() => { + const handleScroll = () => setShowBackTop(window.scrollY > 300) + window.addEventListener('scroll', handleScroll, { passive: true }) + return () => window.removeEventListener('scroll', handleScroll) + }, []) + + const scrollToTop = () => window.scrollTo({ top: 0, behavior: 'smooth' }) const [predictingId, setPredictingId] = useState(null) const [prediction, setPrediction] = useState(null) const [predictionFor, setPredictionFor] = useState(null) @@ -682,6 +692,18 @@ export default function Matches() { )} + {/* 回到顶部按钮 */} + ) } diff --git a/frontend/src/pages/Standings.tsx b/frontend/src/pages/Standings.tsx index c864e2d..7438ffc 100644 --- a/frontend/src/pages/Standings.tsx +++ b/frontend/src/pages/Standings.tsx @@ -69,6 +69,16 @@ export default function StandingsPage() { const [loading, setLoading] = useState(true) const [switching, setSwitching] = useState(false) // 切换联赛中 const [error, setError] = useState(null) + const [showBackTop, setShowBackTop] = useState(false) // 回到顶部按钮显示态 + + // 监听滚动,超过 300px 显示回到顶部按钮 + useEffect(() => { + const handleScroll = () => setShowBackTop(window.scrollY > 300) + window.addEventListener('scroll', handleScroll, { passive: true }) + return () => window.removeEventListener('scroll', handleScroll) + }, []) + + const scrollToTop = () => window.scrollTo({ top: 0, behavior: 'smooth' }) const load = useCallback(async (code?: string) => { setLoading(true) @@ -211,6 +221,19 @@ export default function StandingsPage() { )} + + {/* 回到顶部按钮 */} + ) }