feat: 重构应用加载流程和动画管理
- 新增 AppLoader 组件作为全局加载器 - 引入 Pinia 状态管理应用加载状态 - 创建 usePageScrollLock 组合式函数管理滚动锁定 - 重构首页动画流程,使用 Promise 链式调用 - 移除旧的 HomeLoader 组件 - 优化头部导航栏的入场动画触发逻辑
This commit is contained in:
@@ -1,16 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { ref, onBeforeUnmount } from 'vue'
|
||||
import gsap from 'gsap'
|
||||
|
||||
const introTitle = 'ArcticNewOne'
|
||||
const introLetters = introTitle.split('')
|
||||
|
||||
const introRef = ref<HTMLElement | null>(null)
|
||||
const introTitleRef = ref<HTMLElement | null>(null)
|
||||
let ctx: gsap.Context | null = null
|
||||
|
||||
defineExpose({
|
||||
introRef,
|
||||
introTitleRef
|
||||
const play = () => new Promise<void>((resolve) => {
|
||||
if (!introRef.value || !introTitleRef.value) return resolve()
|
||||
|
||||
const chars = gsap.utils.toArray('.hero-intro-char', introRef.value)
|
||||
const tm = introRef.value.querySelector('.hero-intro-tm')
|
||||
|
||||
if (!chars.length || !tm) return resolve()
|
||||
|
||||
ctx = gsap.context(() => {
|
||||
// 初始化样式
|
||||
gsap.set(introRef.value, { display: 'grid', yPercent: 0, autoAlpha: 1 })
|
||||
gsap.set(introTitleRef.value, { y: 0, autoAlpha: 1 })
|
||||
gsap.set(chars, { y: 0, yPercent: 110 })
|
||||
gsap.set(tm, { autoAlpha: 0 })
|
||||
|
||||
gsap.timeline({
|
||||
defaults: { ease: 'power3.out' },
|
||||
onComplete: () => {
|
||||
gsap.set(introRef.value, { display: 'none' })
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
// 逐字升起
|
||||
.to(chars, { yPercent: 0, duration: 0.75, stagger: 0.055 })
|
||||
// TM 渐显
|
||||
.to(tm, { autoAlpha: 1, duration: 0.4, ease: 'power2.out' })
|
||||
// 停顿 0.35s 后,整体上移并淡出标题
|
||||
.addLabel('introOut', '+=0.35')
|
||||
.to(introTitleRef.value, { autoAlpha: 0, duration: 1.05, ease: 'power4.inOut' }, 'introOut')
|
||||
.to(introRef.value, { yPercent: -100, duration: 1.05, ease: 'power4.inOut' }, 'introOut')
|
||||
}, introRef.value)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => ctx?.revert())
|
||||
|
||||
defineExpose({ play })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -35,7 +68,7 @@ defineExpose({
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 80;
|
||||
display: grid;
|
||||
display: none;
|
||||
place-items: center;
|
||||
overflow: hidden;
|
||||
color: #fff;
|
||||
|
||||
Reference in New Issue
Block a user