Skip to content

Commit 59b3ce7

Browse files
Merge pull request #25 from pavanydg/main
added scroll to top button
2 parents ca6d2cb + 6b1c5bf commit 59b3ce7

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

layouts/_default/baseof.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,43 @@
1616
{{ end }}
1717
</main>
1818

19+
<button id="scrollToTop" class="scroll-to-top"><div class="topArrow">
20+
21+
</div></button>
22+
1923
{{ block "footer.html" . }}
2024
{{ partialCached "footer.html" . }}
2125
{{ end }}
2226

2327
{{ block "scripts" . }}
2428
{{ partial "scripts" . }}
29+
30+
31+
<script>
32+
document.addEventListener("DOMContentLoaded", () => {
33+
const scrollToTopButton = document.getElementById("scrollToTop");
34+
35+
window.addEventListener("scroll", () => {
36+
if (window.scrollY > 300) {
37+
scrollToTopButton.style.display = "block";
38+
} else {
39+
scrollToTopButton.style.display = "none";
40+
}
41+
});
42+
43+
scrollToTopButton.addEventListener("click", () => {
44+
window.scrollTo({
45+
top: 0,
46+
behavior: "smooth"
47+
});
48+
});
49+
});
50+
</script>
51+
52+
<style>
53+
54+
</style>
55+
2556
{{ end }}
2657

2758
</body>

static/theme.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,33 @@ body>header nav a.active {
301301
display: none
302302
}
303303

304+
.scroll-to-top {
305+
display: none;
306+
position: fixed;
307+
bottom: 20px;
308+
right: 20px;
309+
padding: 10px 15px;
310+
background-color: #007BFF;
311+
color: black;
312+
border: none;
313+
height: 60px;
314+
width: 60px;
315+
border-radius: 50%;
316+
cursor: pointer;
317+
z-index: 1000;
318+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
319+
}
320+
321+
.scroll-to-top:hover {
322+
background-color: #0056b3;
323+
}
324+
.topArrow{
325+
font-size: 40px;
326+
position: relative;
327+
bottom: 55px;
328+
color: white;
329+
}
330+
304331
@media (max-width:71.24em) {
305332
body>header {
306333
flex-wrap: wrap

0 commit comments

Comments
 (0)