fix: 修复所有首页板块 pin 滚动不连贯问题

🐛 问题根源:
每个板块有两套独立的 ScrollTrigger 在同一个元素上:
- 入场动画用独立的 scrollTrigger
- pin 效果用 ScrollTrigger.create
两者互相冲突,导致空白间隙和动画跳变

 修复方案:
将所有板块的入场动画和 pin 滚动合并为一个统一时间线(timeline),
确保动画从 pin 开始到结束完全连续,无空白区

🔧 修复的 6 个板块:
1. HomeTestimonials - 标题入场 + 卡片逐张切换(淡入淡出)
2. HomeServices - 标题入场 + 卡片飞入归位 + 逐张聚焦
3. HomeAchievements - 逐个成就项展示(前一个淡出,后一个淡入)
4. HomeTechStack - 内容入场 + 标签散开 + 球体旋转
5. HomeProcess - 标题入场 + 线条绘制 + 步骤逐个出现 + 横向滚动
6. HomeUpdates - 标题入场 + 卡片分批出现

🎯 效果:
- pin 期间动画完全连续,无空白间隙
- 入场和 pin 共享同一个 timeline
- scrub: 0.5 让滚动更平滑
- 每个板块到下一个板块无缝过渡

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
陈春
2026-06-03 19:53:46 +08:00
parent bb0020b406
commit 02323fd426
6 changed files with 161 additions and 307 deletions
+19 -37
View File
@@ -164,63 +164,45 @@ onMounted(async () => {
if (!rootRef.value || !headerRef.value) return
ctx = gsap.context(() => {
// 标题动画
gsap.fromTo(headerRef.value,
{ autoAlpha: 0, y: 50 },
{
scrollTrigger: {
trigger: headerRef.value,
start: 'top 80%',
toggleActions: 'play none none reverse'
},
autoAlpha: 1,
y: 0,
duration: 1,
ease: 'power3.out'
}
)
// Pin 效果:固定板块,逐行展示卡片
const totalCards = updates.length
const timeline = gsap.timeline()
// 初始隐藏所有卡片
// 初始状态
gsap.set(headerRef.value, { autoAlpha: 0, y: 50 })
cardElements.value.forEach((card) => {
if (!card) return
gsap.set(card, { autoAlpha: 0, y: 60, scale: 0.9 })
})
// 分批展示:每批展示一行(按顺序,每行 2-3 个)
const batchSize = 3
// 统一时间线
const tl = gsap.timeline()
// 第一屏:标题入场
tl.to(headerRef.value, { autoAlpha: 1, y: 0, duration: 0.8, ease: 'power3.out' }, 0)
// 分批展示卡片:每批 2 个,逐批出现
const totalCards = updates.length
const batchSize = 2
const batches = Math.ceil(totalCards / batchSize)
for (let batch = 0; batch < batches; batch++) {
timeline.addLabel(`batch-${batch}`)
const pos = 0.8 + batch
const start = batch * batchSize
const end = Math.min(start + batchSize, totalCards)
for (let i = start; i < end; i++) {
if (!cardElements.value[i]) continue
timeline.to(cardElements.value[i], {
autoAlpha: 1,
y: 0,
scale: 1,
duration: 0.8,
ease: 'power3.out',
}, `batch-${batch}+=${(i - start) * 0.15}`)
tl.to(cardElements.value[i], {
autoAlpha: 1, y: 0, scale: 1,
duration: 0.7, ease: 'power3.out',
}, pos + (i - start) * 0.12)
}
}
ScrollTrigger.create({
trigger: rootRef.value,
start: 'top top',
end: () => `+=${batches * window.innerHeight}`,
end: () => `+=${(batches + 1) * window.innerHeight}`,
pin: true,
scrub: true,
scrub: 0.5,
anticipatePin: 1,
animation: timeline,
animation: tl,
})
}, rootRef.value)
})