Skip to content

Compatability

Library use dynamic import when initiating LocomotiveScroll in _init method there.

Next means that project can be safely imported in Node.js environment and doesn't require additional setup.

ts
// ...

const scrollCallback = (v: ILenisScrollValues) => {
if (direction != v.direction) {
  potiah.direction = direction = v.direction as 1 | -1
}
}

const { default: LocomotiveScroll } = await import('locomotive-scroll') 

// @ts-expect-error
const loco = markRaw<ILocomotiveScroll>(new LocomotiveScroll({ ...defOptions, ...opt, scrollCallback }))

// wait when Core, Lenis instances are created
await new Promise((resolve) => {
requestAnimationFrame(() => resolve(null))
})

// ...
// ...

const scrollCallback = (v: ILenisScrollValues) => {
if (direction != v.direction) {
  potiah.direction = direction = v.direction as 1 | -1
}
}

const { default: LocomotiveScroll } = await import('locomotive-scroll') 

// @ts-expect-error
const loco = markRaw<ILocomotiveScroll>(new LocomotiveScroll({ ...defOptions, ...opt, scrollCallback }))

// wait when Core, Lenis instances are created
await new Promise((resolve) => {
requestAnimationFrame(() => resolve(null))
})

// ...