Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
671 B
2
Indexable
Never
import Lenis from '@studio-freight/lenis'

const lenis = ref(null)

export const createLenis = () => {
  onMounted(() => {
    if (!lenis.value) {
      lenis.value = new Lenis({
        duration: 0.6,
        easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // https://www.desmos.com/calculator/brs54l4xou
      })
    }

    function raf(time) {
      lenis.value.raf(time)
      requestAnimationFrame(raf)
    }

    requestAnimationFrame(raf)
  })

  onUnmounted(() => {
    if (lenis.value) {
      lenis.value.destroy()
      lenis.value = null
    }
  })

  return lenis
}

export const useLenis = () => {
  return lenis
}