lenis 滚动质感

This commit is contained in:
tangly1024
2025-04-12 20:48:48 +08:00
parent 9e68ec7eb5
commit 31d0f6d578
2 changed files with 32 additions and 3 deletions

View File

@@ -2,8 +2,6 @@
* 鼠标滚动阻尼感
*/
import { useEffect } from 'react'
// import anime from 'animejs'
import { siteConfig } from '@/lib/config'
import { loadExternalResource } from '@/lib/utils'
/**
@@ -16,10 +14,39 @@ const Lenis = () => {
// 异步加载
async function loadLenis() {
loadExternalResource(
'https://unpkg.com/lenis@1.2.3/dist/lenis.mjs',
'/js/lenis.js',
'js'
).then(() => {
console.log('Lenis',window.Lenis)
if(!window.Lenis) {
console.error('Lenis not loaded')
return
}
const Lenis = window.Lenis
// 创建 Lenis 实例
const lenis = new Lenis({
duration: 1.2,
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // https://www.desmos.com/calculator/brs54l4xou
direction: 'vertical', // vertical, horizontal
gestureDirection: 'vertical', // vertical, horizontal, both
smooth: true,
mouseMultiplier: 1,
smoothTouch: false,
touchMultiplier: 2,
infinite: false,
})
//get scroll value
lenis.on('scroll', ({ scroll, limit, velocity, direction, progress }) => { console.log({ scroll, limit, velocity, direction, progress })
})
function raf(time) {
lenis.raf(time)
requestAnimationFrame(raf)
}
requestAnimationFrame(raf)
})
}

2
public/js/lenis.js Normal file

File diff suppressed because one or more lines are too long