From af898f1cfed66f1a2319e1c43832dfff673ff2e6 Mon Sep 17 00:00:00 2001 From: chenchun Date: Sun, 26 Apr 2026 21:58:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E9=A1=B5=E9=9D=A2=E5=8A=A8=E7=94=BB):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E5=BC=95=E7=94=A8=E5=92=8C=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除未使用的 introCharRefs 引用,改用 gsap.utils.toArray 获取字符元素 将 '.hero-intro-tm' 选择器结果缓存为 tmElement 避免重复查询 为静态元素添加 v-once 指令提升性能 调整部分元素的初始 opacity 和 visibility 状态 --- app/pages/index.vue | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/pages/index.vue b/app/pages/index.vue index 5fe7d2b..998074a 100644 --- a/app/pages/index.vue +++ b/app/pages/index.vue @@ -54,7 +54,6 @@ const loaderRef = ref(null) const loaderBarRef = ref(null) const introRef = ref(null) const introTitleRef = ref(null) -const introCharRefs = ref([]) const heroStageRef = ref(null) const heroRef = ref(null) const heroPanelRef = ref(null) @@ -96,10 +95,11 @@ onMounted(() => { } const introCharElements = gsap.utils.toArray('.hero-intro-char', introElement) + const tmElement = introElement.querySelector('.hero-intro-tm') - if (introCharElements.length === 0) { - return - } + if (introCharElements.length === 0 || !tmElement) { + return + } const { $lenis } = useNuxtApp() as ReturnType & { $lenis?: Lenis } const topHeader = document.querySelector('.site-header-top') @@ -210,10 +210,10 @@ onMounted(() => { y: 0, autoAlpha: 1, }) - .set('.hero-intro-tm', { + .set(tmElement, { autoAlpha: 0, }) - .fromTo(gsap.utils.toArray('.hero-intro-char', introElement), { + .fromTo(introCharElements, { yPercent: 110, y: 0, }, { @@ -222,7 +222,7 @@ onMounted(() => { duration: 0.75, stagger: 0.055, }) - .to('.hero-intro-tm', { + .to(tmElement, { autoAlpha: 1, duration: 0.4, ease: 'power2.out', @@ -271,7 +271,7 @@ onMounted(() => { gsap.set(introTitleElement, { y: 0, autoAlpha: 1 }) // 强制清除 CSS 中的 translateY 像素值,避免被 GSAP 解析为固定 y 像素导致一直不可见 gsap.set(introCharElements, { y: 0, yPercent: 110 }) - gsap.set('.hero-intro-tm', { autoAlpha: 0 }) + gsap.set(tmElement, { autoAlpha: 0 }) gsap.set(heroElement, { yPercent: 100 }) if (topHeader) { gsap.set(topHeader, { yPercent: -140, autoAlpha: 0 }) @@ -336,7 +336,7 @@ onBeforeUnmount(() => { :data-demo-user="demoUserName" :data-demo-user-role="demoUserRole" > -