feat(lenis): add smooth scroll solution
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import Lenis from 'lenis';
|
||||
import {
|
||||
getContext,
|
||||
setContext,
|
||||
} from 'svelte';
|
||||
|
||||
const LENIS_KEY = Symbol('lenis');
|
||||
|
||||
export function createLenisContext() {
|
||||
let lenis = $state<Lenis | null>(null);
|
||||
|
||||
return {
|
||||
get lenis() {
|
||||
return lenis;
|
||||
},
|
||||
setLenis(instance: Lenis) {
|
||||
lenis = instance;
|
||||
},
|
||||
destroyLenis() {
|
||||
lenis?.destroy();
|
||||
lenis = null;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function setLenisContext(context: ReturnType<typeof createLenisContext>) {
|
||||
setContext(LENIS_KEY, context);
|
||||
}
|
||||
|
||||
export function getLenisContext() {
|
||||
return getContext<ReturnType<typeof createLenisContext>>(LENIS_KEY);
|
||||
}
|
||||
Reference in New Issue
Block a user