feat: 为首页新增板块添加 ScrollTrigger pin 滚动效果

 新增 pin 效果(板块固定,内容随滚动切换):

1. HomeTestimonials - 客户评价
   - 固定板块,滚动自动切换卡片
   - 每屏切换一张评价卡片

2. HomeTechStack - 技术栈
   - 固定板块,3D 球体自动旋转一圈
   - 滚动控制旋转进度

3. HomeProcess - 创意流程
   - 固定板块,横向滚动浏览所有步骤
   - 6 个步骤依次展示

4. HomeServices - 服务能力
   - 固定板块,逐张卡片聚焦展示
   - 聚焦卡片放大,其他缩小变暗
   - 所有卡片飞入归位后逐个聚焦

5. HomeAchievements - 数字成就
   - 固定板块,逐个成就项展示
   - 每个数字滚动计数动画触发

6. HomeUpdates - 最新动态
   - 固定板块,逐批展示卡片
   - 分批出现,每批 3 个卡片

🎯 效果:
- 滚动到板块时自动固定(pin)
- 内部元素随滚动依次展示
- 所有内部元素展示完毕后才继续下一个板块
- 每个板块独特的 pin 动画效果

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
陈春
2026-06-03 19:49:18 +08:00
parent 89c4c4c7b5
commit bb0020b406
6 changed files with 208 additions and 76 deletions
+76 -31
View File
@@ -218,45 +218,90 @@ onMounted(async () => {
}
)
// 卡片入场动画 - 从四周飞入
// Pin 效果:固定板块,逐张卡片聚焦展示
const totalCards = services.length
const timeline = gsap.timeline()
// 初始:所有卡片从四周飞入并归位
cardElements.value.forEach((card, index) => {
if (!card) return
const positions = [
{ x: -200, y: -200 }, // 左上
{ x: 0, y: -200 }, // 上
{ x: 200, y: -200 }, // 右上
{ x: -200, y: 200 }, // 左下
{ x: 0, y: 200 }, // 下
{ x: 200, y: 200 } // 右下
{ x: -200, y: -200, rotate: -15 },
{ x: 0, y: -200, rotate: 10 },
{ x: 200, y: -200, rotate: -15 },
{ x: -200, y: 200, rotate: 15 },
{ x: 0, y: 200, rotate: -10 },
{ x: 200, y: 200, rotate: 15 }
]
const startPos = positions[index]
gsap.fromTo(card,
{
autoAlpha: 0,
x: startPos.x,
y: startPos.y,
scale: 0.8,
rotateZ: index % 2 === 0 ? -15 : 15
},
{
scrollTrigger: {
trigger: card,
start: 'top 85%',
toggleActions: 'play none none reverse'
},
autoAlpha: 1,
x: 0,
y: 0,
scale: 1,
rotateZ: 0,
duration: 1.2,
delay: index * 0.1,
ease: 'back.out(1.2)'
gsap.set(card, {
autoAlpha: 0,
x: startPos.x,
y: startPos.y,
scale: 0.8,
rotateZ: startPos.rotate,
})
// 第一屏:所有卡片飞入归位
timeline.to(card, {
autoAlpha: 1,
x: 0,
y: 0,
scale: 1,
rotateZ: 0,
duration: 1,
ease: 'back.out(1.2)',
}, index * 0.1)
})
// 后续屏:每次聚焦一张卡片(放大),其他缩小
for (let focus = 0; focus < totalCards; focus++) {
timeline.addLabel(`focus-${focus}`, focus + 1)
cardElements.value.forEach((card, index) => {
if (!card) return
timeline.to(card, {
scale: index === focus ? 1.05 : 0.85,
autoAlpha: index === focus ? 1 : 0.4,
zIndex: index === focus ? 10 : 1,
duration: 0.6,
ease: 'power2.out',
}, `focus-${focus}`)
// 聚焦的卡片翻转展示背面
if (index === focus) {
timeline.call(() => handleCardHover(focus, true), [], `focus-${focus}`)
} else {
timeline.call(() => handleCardHover(index, false), [], `focus-${focus}`)
}
)
})
}
// 最后:恢复所有卡片正常状态
timeline.addLabel('reset')
cardElements.value.forEach((card, index) => {
if (!card) return
timeline.to(card, {
scale: 1,
autoAlpha: 1,
zIndex: 1,
duration: 0.5,
ease: 'power2.out',
}, 'reset')
timeline.call(() => handleCardHover(index, false), [], 'reset')
})
ScrollTrigger.create({
trigger: rootRef.value,
start: 'top top',
end: () => `+=${(totalCards + 2) * window.innerHeight}`,
pin: true,
scrub: true,
anticipatePin: 1,
animation: timeline,
})
}, rootRef.value)
})