Skip to content

Commit 9e18d24

Browse files
author
CodeJudge
committed
feat: 回到顶部按钮
1 parent 69f2b4f commit 9e18d24

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

frontend/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Footer from './components/Footer';
55
import ErrorBoundary from './components/ErrorBoundary';
66
import KeyboardShortcuts from './components/KeyboardShortcuts';
77
import TutorialOverlay from './components/TutorialOverlay';
8+
import BackToTop from './components/BackToTop';
89

910
const Home = lazy(() => import('./pages/Home'));
1011
const Login = lazy(() => import('./pages/Login'));
@@ -53,6 +54,7 @@ export default function App() {
5354
</main>
5455
<KeyboardShortcuts />
5556
<TutorialOverlay />
57+
<BackToTop />
5658
</div>
5759
);
5860
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { useState, useEffect } from 'react';
2+
import { ArrowUp } from 'lucide-react';
3+
4+
export default function BackToTop() {
5+
const [visible, setVisible] = useState(false);
6+
7+
useEffect(() => {
8+
const handler = () => setVisible(window.scrollY > 400);
9+
window.addEventListener('scroll', handler, { passive: true });
10+
return () => window.removeEventListener('scroll', handler);
11+
}, []);
12+
13+
if (!visible) return null;
14+
15+
return (
16+
<button
17+
onClick={() => window.scrollTo({ top: 0, behavior: 'smooth' })}
18+
className="fixed bottom-8 right-8 z-50 w-10 h-10 bg-primary-600 hover:bg-primary-500 text-white rounded-full shadow-lg shadow-primary-600/25 flex items-center justify-center transition-all duration-200 hover:scale-110"
19+
title="回到顶部"
20+
>
21+
<ArrowUp className="w-5 h-5" />
22+
</button>
23+
);
24+
}

frontend/tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"root":["./src/app.tsx","./src/main.tsx","./src/components/choicequestion.tsx","./src/components/codeeditor.tsx","./src/components/dailygoal.tsx","./src/components/errorboundary.tsx","./src/components/fillblankquestion.tsx","./src/components/footer.tsx","./src/components/gamificationsection.tsx","./src/components/keyboardshortcuts.tsx","./src/components/markdownrenderer.tsx","./src/components/navbar.tsx","./src/components/problemcard.tsx","./src/components/submissionstatus.tsx","./src/components/tutorialoverlay.tsx","./src/context/authcontext.tsx","./src/context/bookmarkcontext.tsx","./src/hooks/usedocumenttitle.ts","./src/pages/admin.tsx","./src/pages/adminproblemform.tsx","./src/pages/apidocs.tsx","./src/pages/home.tsx","./src/pages/leaderboard.tsx","./src/pages/login.tsx","./src/pages/notfound.tsx","./src/pages/problemdetail.tsx","./src/pages/problems.tsx","./src/pages/profile.tsx","./src/pages/register.tsx","./src/pages/submissions.tsx","./src/pages/systemhealth.tsx","./src/services/api.ts","./src/types/index.ts"],"version":"5.9.3"}
1+
{"root":["./src/app.tsx","./src/main.tsx","./src/components/backtotop.tsx","./src/components/choicequestion.tsx","./src/components/codeeditor.tsx","./src/components/dailygoal.tsx","./src/components/errorboundary.tsx","./src/components/fillblankquestion.tsx","./src/components/footer.tsx","./src/components/gamificationsection.tsx","./src/components/keyboardshortcuts.tsx","./src/components/markdownrenderer.tsx","./src/components/navbar.tsx","./src/components/problemcard.tsx","./src/components/submissionstatus.tsx","./src/components/tutorialoverlay.tsx","./src/context/authcontext.tsx","./src/context/bookmarkcontext.tsx","./src/hooks/usedocumenttitle.ts","./src/pages/admin.tsx","./src/pages/adminproblemform.tsx","./src/pages/apidocs.tsx","./src/pages/home.tsx","./src/pages/leaderboard.tsx","./src/pages/login.tsx","./src/pages/notfound.tsx","./src/pages/problemdetail.tsx","./src/pages/problems.tsx","./src/pages/profile.tsx","./src/pages/register.tsx","./src/pages/submissions.tsx","./src/pages/systemhealth.tsx","./src/services/api.ts","./src/types/index.ts"],"version":"5.9.3"}

0 commit comments

Comments
 (0)