2022-05-12 09:29:55 +00:00
|
|
|
<template>
|
|
|
|
<Transition name="fade">
|
2024-04-04 22:20:42 +00:00
|
|
|
<button
|
|
|
|
v-show="showing"
|
|
|
|
ref="el"
|
|
|
|
class="sm:hidden block fixed right-[1.8rem] z-20 opacity-100 duration-500 transition-opacity rounded-full py-2 px-4 bg-black/50"
|
2024-04-23 21:01:27 +00:00
|
|
|
title="Scroll to top"
|
2024-04-04 22:20:42 +00:00
|
|
|
type="button"
|
|
|
|
@click="scrollToTop"
|
|
|
|
>
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="faCircleUp" />
|
2022-07-15 07:23:55 +00:00
|
|
|
Top
|
2022-05-12 09:29:55 +00:00
|
|
|
</button>
|
|
|
|
</Transition>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2022-07-15 07:23:55 +00:00
|
|
|
import { faCircleUp } from '@fortawesome/free-solid-svg-icons'
|
2022-05-12 09:29:55 +00:00
|
|
|
import { onMounted, ref } from 'vue'
|
|
|
|
import { $ } from '@/utils'
|
|
|
|
|
|
|
|
const el = ref<HTMLElement>()
|
|
|
|
const showing = ref(false)
|
|
|
|
|
|
|
|
const scrollToTop = () => $.scrollTo(el.value?.parentElement!, 0, 500, () => (showing.value = false))
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
el.value?.parentElement?.addEventListener('scroll', event => {
|
|
|
|
showing.value = (event.target as HTMLElement).scrollTop > 64
|
|
|
|
})
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
2024-04-04 20:13:35 +00:00
|
|
|
<style lang="postcss" scoped>
|
2022-05-12 09:29:55 +00:00
|
|
|
button {
|
2024-04-04 22:20:42 +00:00
|
|
|
@apply border border-white/50 text-k-text-primary;
|
2022-10-13 15:18:47 +00:00
|
|
|
bottom: calc(var(--footer-height) + 26px);
|
2022-05-12 09:29:55 +00:00
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
&.fade-enter, &.fade-leave-to {
|
|
|
|
@apply opacity-0;
|
2022-05-12 09:29:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|