feat. ScrollTop 버튼 추가
This commit is contained in:
69
layers/components/atoms/Button/ScrollTop.vue
Normal file
69
layers/components/atoms/Button/ScrollTop.vue
Normal file
@@ -0,0 +1,69 @@
|
||||
<script setup lang="ts">
|
||||
interface Props {
|
||||
parentRef: HTMLElement | null
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const { y: windowY } = useWindowScroll({ behavior: 'smooth' })
|
||||
const { height: viewportH } = useWindowSize()
|
||||
|
||||
const parentEl = toRef(props, 'parentRef')
|
||||
const { bottom: parentBottom } = useElementBounding(parentEl)
|
||||
|
||||
const showBtn = computed(() => windowY.value > 0)
|
||||
|
||||
const offsetY = 12
|
||||
|
||||
const pinToParent = computed(() => {
|
||||
if (!parentBottom.value) return false
|
||||
return parentBottom.value <= viewportH.value - offsetY
|
||||
})
|
||||
|
||||
const positionClasses = computed(() =>
|
||||
pinToParent.value
|
||||
? 'absolute bottom-[12px] right-[12px] md:bottom-[40px] md:right-[40px]'
|
||||
: 'fixed bottom-[12px] right-[12px] md:bottom-[40px] md:right-[40px]'
|
||||
)
|
||||
|
||||
const handleScrollToTop = () => {
|
||||
windowY.value = 0
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Transition name="fade">
|
||||
<button
|
||||
v-if="showBtn"
|
||||
:class="['btn-top', positionClasses]"
|
||||
@click="handleScrollToTop"
|
||||
>
|
||||
<AtomsIconsTopLine class="icon-top" />
|
||||
<span class="sr-only">top</span>
|
||||
</button>
|
||||
</Transition>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.btn-top {
|
||||
@apply rounded-full flex items-center justify-center bg-black/20 z-[100]
|
||||
w-[40px] h-[40px] md:w-[48px] md:h-[48px]
|
||||
before:content-[''] before:absolute before:top-0 before:left-0 before:w-full before:h-full before:border before:border-[rgba(255,255,255,0.06)] before:rounded-full before:transition-all before:duration-300 before:ease-in-out
|
||||
after:content-[''] after:absolute after:top-0 after:left-0 after:w-full after:h-full after:bg-white after:rounded-full after:opacity-0 after:transition-all after:duration-300 after:ease-in-out;
|
||||
}
|
||||
.btn-top:hover {
|
||||
@apply after:opacity-10;
|
||||
}
|
||||
.btn-top:hover .icon-top {
|
||||
@apply opacity-100;
|
||||
}
|
||||
.icon-top {
|
||||
@apply opacity-50 transition-opacity duration-300 ease-in-out;
|
||||
}
|
||||
|
||||
[data-theme='light'] {
|
||||
.btn-top {
|
||||
@apply bg-white/10;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
30
layers/components/atoms/icons/TopLine.vue
Normal file
30
layers/components/atoms/icons/TopLine.vue
Normal file
@@ -0,0 +1,30 @@
|
||||
<script setup lang="ts">
|
||||
interface Props {
|
||||
size?: number | string
|
||||
color?: string
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
size: 24,
|
||||
color: 'white',
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
:width="size"
|
||||
:height="size"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
>
|
||||
<path
|
||||
d="M13 9.41422L17.2929 13.7071C17.6834 14.0976 18.3166 14.0976 18.7071 13.7071C19.0976 13.3166 19.0976 12.6834 18.7071 12.2929L12.7078 6.29361C12.5289 6.1143 12.2822 6.00257 12.0094 6.00005C12.0063 6.00002 12.0032 6.00001 12 6.00001C11.9968 6.00001 11.9937 6.00002 11.9906 6.00005C11.7269 6.00249 11.4877 6.10694 11.3104 6.27585C11.3045 6.28145 11.2987 6.28714 11.2929 6.2929L5.29289 12.2929C4.90237 12.6834 4.90237 13.3166 5.29289 13.7071C5.68341 14.0976 6.31658 14.0976 6.7071 13.7071L11 9.41422L11 20C11 20.5523 11.4477 21 12 21C12.5523 21 13 20.5523 13 20L13 9.41422Z"
|
||||
:fill="color"
|
||||
/>
|
||||
<path
|
||||
d="M19.5 4.00001C19.5 4.55229 19.0523 5 18.5 5L5.5 5C4.94771 5 4.5 4.55228 4.5 4C4.5 3.44772 4.94771 3 5.5 3L18.5 3C19.0523 3 19.5 3.44772 19.5 4.00001Z"
|
||||
:fill="color"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
Reference in New Issue
Block a user