42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import { useWindowScroll } from '@vueuse/core'
|
|
|
|
export const useScrollStore = defineStore('scrollStore', () => {
|
|
const { y: windowY } = useWindowScroll({ behavior: 'smooth' })
|
|
|
|
const stoveGnbHeight = 48 as number
|
|
const isPassedStoveGnb = ref(false)
|
|
const scrollGnbPosition = ref(stoveGnbHeight)
|
|
|
|
const updateScrollValue = () => {
|
|
if (stoveGnbHeight <= windowY.value) {
|
|
isPassedStoveGnb.value = true
|
|
scrollGnbPosition.value = 0
|
|
} else {
|
|
isPassedStoveGnb.value = false
|
|
if (windowY.value === 0) {
|
|
scrollGnbPosition.value = stoveGnbHeight
|
|
} else {
|
|
scrollGnbPosition.value = stoveGnbHeight - windowY.value
|
|
}
|
|
}
|
|
}
|
|
|
|
const controlScrollLock = (state: boolean) => {
|
|
if (state) {
|
|
document.body.classList.add('scroll-lock')
|
|
} else {
|
|
document.body.classList.remove('scroll-lock')
|
|
}
|
|
}
|
|
|
|
return {
|
|
stoveGnbHeight,
|
|
isPassedStoveGnb,
|
|
scrollGnbPosition,
|
|
|
|
updateScrollValue,
|
|
controlScrollLock,
|
|
}
|
|
})
|