Skip to content

Commit

Permalink
Merge pull request #25 from pavanydg/main
Browse files Browse the repository at this point in the history
added scroll to top button
  • Loading branch information
DhairyaMajmudar authored Dec 18, 2024
2 parents ca6d2cb + 6b1c5bf commit 59b3ce7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
31 changes: 31 additions & 0 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,43 @@
{{ end }}
</main>

<button id="scrollToTop" class="scroll-to-top"><div class="topArrow">
</div></button>

{{ block "footer.html" . }}
{{ partialCached "footer.html" . }}
{{ end }}

{{ block "scripts" . }}
{{ partial "scripts" . }}


<script>
document.addEventListener("DOMContentLoaded", () => {
const scrollToTopButton = document.getElementById("scrollToTop");

window.addEventListener("scroll", () => {
if (window.scrollY > 300) {
scrollToTopButton.style.display = "block";
} else {
scrollToTopButton.style.display = "none";
}
});

scrollToTopButton.addEventListener("click", () => {
window.scrollTo({
top: 0,
behavior: "smooth"
});
});
});
</script>

<style>

</style>

{{ end }}

</body>
Expand Down
27 changes: 27 additions & 0 deletions static/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,33 @@ body>header nav a.active {
display: none
}

.scroll-to-top {
display: none;
position: fixed;
bottom: 20px;
right: 20px;
padding: 10px 15px;
background-color: #007BFF;
color: black;
border: none;
height: 60px;
width: 60px;
border-radius: 50%;
cursor: pointer;
z-index: 1000;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.scroll-to-top:hover {
background-color: #0056b3;
}
.topArrow{
font-size: 40px;
position: relative;
bottom: 55px;
color: white;
}

@media (max-width:71.24em) {
body>header {
flex-wrap: wrap
Expand Down

0 comments on commit 59b3ce7

Please sign in to comment.