2024-04-14 08:52:52 +00:00
|
|
|
<button class="top-btn hidden">
|
|
|
|
<img src="/assets/images/elements/top.svg" alt="Scroll to top">
|
2024-04-11 15:42:11 +00:00
|
|
|
</button>
|
|
|
|
|
2024-04-14 08:52:52 +00:00
|
|
|
<style>
|
2024-04-11 15:42:11 +00:00
|
|
|
.top-btn {
|
|
|
|
position: fixed;
|
|
|
|
bottom: 20px;
|
|
|
|
right: 20px;
|
|
|
|
z-index: 999;
|
|
|
|
border: none;
|
|
|
|
background-color: var(--clr-top-btn);
|
|
|
|
border-radius: 50em;
|
|
|
|
padding: 0.5em;
|
|
|
|
}
|
|
|
|
|
|
|
|
.top-btn:focus {
|
|
|
|
outline: 0.25em solid var(--clr-top-btn);
|
|
|
|
outline-offset: 0.15em;
|
|
|
|
}
|
|
|
|
|
|
|
|
.top-btn img {
|
|
|
|
width: 2rem;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2024-04-14 08:52:52 +00:00
|
|
|
<script defer>
|
2024-04-11 15:42:11 +00:00
|
|
|
const topButton = document.querySelector(".top-btn");
|
|
|
|
|
|
|
|
window.onscroll = () => {
|
|
|
|
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
|
|
|
|
topButton.classList.remove("hidden");
|
|
|
|
} else {
|
|
|
|
topButton.classList.add("hidden");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
topButton.addEventListener('click', () => {
|
|
|
|
window.scrollTo({
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
behavior: "smooth",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|