3173bd3cd6
- 在 lenis.client.ts 中提供 lenis 实例供全局使用 - 添加首页入场动画,包含字母动画和过渡效果 - 优化滚动行为,入场期间锁定滚动 - 修复自定义光标初始位置问题 - 调整页面布局样式,隐藏滚动条 - 更新头部组件类名以匹配新设计
37 lines
982 B
TypeScript
37 lines
982 B
TypeScript
import Lenis from 'lenis'
|
|
import 'lenis/dist/lenis.css'
|
|
import gsap from 'gsap'
|
|
import { ScrollTrigger } from 'gsap/ScrollTrigger'
|
|
|
|
gsap.registerPlugin(ScrollTrigger)
|
|
|
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
// 用 Lenis 平滑浏览器原始 wheel 输入,避免鼠标滚轮一格跳太远。
|
|
const lenis = new Lenis({
|
|
lerp: 0.075,
|
|
wheelMultiplier: 0.7,
|
|
})
|
|
|
|
const updateLenis = (time: number) => {
|
|
lenis.raf(time * 1000)
|
|
}
|
|
|
|
// ScrollTrigger 必须跟随 Lenis 的平滑滚动值更新,否则触发点会和真实视觉滚动不同步。
|
|
lenis.on('scroll', ScrollTrigger.update)
|
|
gsap.ticker.add(updateLenis)
|
|
gsap.ticker.lagSmoothing(0)
|
|
|
|
// Nuxt 卸载时清掉 ticker 和事件,避免热更新或页面销毁后重复驱动滚动。
|
|
nuxtApp.hook('app:beforeUnmount', () => {
|
|
lenis.off('scroll', ScrollTrigger.update)
|
|
gsap.ticker.remove(updateLenis)
|
|
lenis.destroy()
|
|
})
|
|
|
|
return {
|
|
provide: {
|
|
lenis,
|
|
},
|
|
}
|
|
})
|