Skip to content

Commit fdc769b

Browse files
committed
Add scroll to top button
1 parent 8ecdb5a commit fdc769b

1 file changed

Lines changed: 64 additions & 1 deletion

File tree

frontend/leaderboard.html

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,47 @@
1111
rel="stylesheet"
1212
/>
1313
<link rel="stylesheet" href="styles/main.css" />
14+
<style>
15+
#scrollTopBtn {
16+
position: fixed;
17+
bottom: 20px;
18+
right: 20px;
19+
20+
display: none;
21+
z-index: 999;
22+
23+
padding: 0.7rem 1rem;
24+
25+
font-family: "Fira Code", monospace;
26+
font-size: 0.8rem;
27+
font-weight: 600;
28+
29+
color: var(--green);
30+
background: rgba(0, 0, 0, 0.85);
31+
32+
border: 1px solid var(--green);
33+
border-radius: 6px;
34+
35+
cursor: pointer;
36+
37+
text-shadow: 0 0 5px rgba(0, 255, 100, 0.5);
38+
box-shadow: 0 0 10px rgba(0, 255, 100, 0.15);
39+
40+
transition: all 0.25s ease;
41+
}
42+
43+
#scrollTopBtn:hover {
44+
transform: translateY(-3px);
45+
background: rgba(0, 255, 100, 0.08);
46+
box-shadow:
47+
0 0 12px rgba(0, 255, 100, 0.35),
48+
0 0 20px rgba(0, 255, 100, 0.15);
49+
}
50+
51+
#scrollTopBtn:active {
52+
transform: translateY(0);
53+
}
54+
</style>
1455
<link rel="icon" type="image/png" href="assets/logo.png" />
1556
<script src="js/navbar.js"></script>
1657
</head>
@@ -81,7 +122,7 @@ <h1 class="page-title">Leaderboard</h1>
81122
autocomplete="off"
82123
spellcheck="false"
83124
/>
84-
125+
85126
<span class="search-result-count" id="search-result-count"></span>
86127
<kbd class="search-shortcut" id="search-shortcut">Ctrl+K</kbd>
87128
<button
@@ -145,6 +186,10 @@ <h1 class="page-title">Leaderboard</h1>
145186
</div>
146187
</main>
147188

189+
<button id="scrollTopBtn" aria-label="Scroll to top">
190+
[ ↑ TOP ]
191+
</button>
192+
148193
<script>
149194
document.addEventListener("DOMContentLoaded", () => {
150195
document.querySelectorAll(".tab").forEach((tab) => {
@@ -220,6 +265,24 @@ <h1 class="page-title">Leaderboard</h1>
220265
}
221266
});
222267
clearBtn.style.display = "none";
268+
269+
const scrollTopBtn = document.getElementById("scrollTopBtn");
270+
271+
window.addEventListener("scroll", () => {
272+
if (window.scrollY > 300) {
273+
scrollTopBtn.style.display = "block";
274+
} else {
275+
scrollTopBtn.style.display = "none";
276+
}
277+
});
278+
279+
scrollTopBtn.addEventListener("click", () => {
280+
window.scrollTo({
281+
top: 0,
282+
behavior: "smooth",
283+
});
284+
});
285+
223286
fetchLeaderboardData();
224287
});
225288

0 commit comments

Comments
 (0)