2023-09-29 11:58:14 +08:00
|
|
|
---
|
2024-08-03 16:40:20 +08:00
|
|
|
import { Icon } from 'astro-icon/components'
|
2023-09-29 11:58:14 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
<!-- There can't be a filter on parent element, or it will break `fixed` -->
|
2024-03-12 14:04:58 +08:00
|
|
|
<div class="back-to-top-wrapper hidden lg:block">
|
2024-02-18 18:13:43 +08:00
|
|
|
<div id="back-to-top-btn" class="back-to-top-btn hide flex items-center rounded-2xl overflow-hidden transition" onclick="backToTop()">
|
|
|
|
<button aria-label="Back to Top" class="btn-card h-[3.75rem] w-[3.75rem]">
|
2023-09-29 11:58:14 +08:00
|
|
|
<Icon name="material-symbols:keyboard-arrow-up-rounded" class="mx-auto"></Icon>
|
2024-02-18 18:13:43 +08:00
|
|
|
</button>
|
2023-09-29 11:58:14 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style lang="stylus">
|
|
|
|
.back-to-top-wrapper
|
2024-02-18 18:13:43 +08:00
|
|
|
width: 3.75rem
|
|
|
|
height: 3.75rem
|
2023-09-29 11:58:14 +08:00
|
|
|
position: absolute
|
2023-11-23 23:24:05 +08:00
|
|
|
right: 0
|
2023-09-29 11:58:14 +08:00
|
|
|
top: 0
|
|
|
|
|
|
|
|
.back-to-top-btn
|
|
|
|
color: var(--primary)
|
2024-02-18 18:13:43 +08:00
|
|
|
font-size: 2.25rem
|
2023-09-29 11:58:14 +08:00
|
|
|
font-weight: bold
|
|
|
|
border: none
|
|
|
|
position: fixed
|
2024-02-18 18:13:43 +08:00
|
|
|
bottom: 15rem
|
2023-09-29 11:58:14 +08:00
|
|
|
opacity: 1
|
|
|
|
cursor: pointer
|
2024-02-18 18:13:43 +08:00
|
|
|
transform: translateX(5rem)
|
2023-09-29 11:58:14 +08:00
|
|
|
i
|
2024-02-18 18:13:43 +08:00
|
|
|
font-size: 1.75rem
|
2023-09-29 11:58:14 +08:00
|
|
|
&.hide
|
2024-02-18 18:13:43 +08:00
|
|
|
transform: translateX(5rem) scale(0.9)
|
2023-09-29 11:58:14 +08:00
|
|
|
opacity: 0
|
|
|
|
pointer-events: none
|
2023-11-23 23:24:05 +08:00
|
|
|
&:active
|
2024-02-18 18:13:43 +08:00
|
|
|
transform: translateX(5rem) scale(0.9)
|
2023-09-29 11:58:14 +08:00
|
|
|
|
|
|
|
</style>
|
|
|
|
|
2024-07-21 18:41:03 +08:00
|
|
|
<script is:raw is:inline>
|
2024-02-18 18:13:43 +08:00
|
|
|
function backToTop() {
|
2023-09-29 11:58:14 +08:00
|
|
|
window.scroll({ top: 0, behavior: 'smooth' });
|
|
|
|
}
|
2024-02-18 18:13:43 +08:00
|
|
|
|
2023-09-29 11:58:14 +08:00
|
|
|
function scrollFunction() {
|
|
|
|
let btn = document.getElementById('back-to-top-btn');
|
|
|
|
if (document.body.scrollTop > 600 || document.documentElement.scrollTop > 600) {
|
|
|
|
btn.classList.remove('hide')
|
|
|
|
} else {
|
|
|
|
btn.classList.add('hide')
|
|
|
|
}
|
|
|
|
}
|
2024-02-18 18:13:43 +08:00
|
|
|
window.onscroll = scrollFunction
|
2023-09-29 11:58:14 +08:00
|
|
|
</script>
|