安装
js动画库
npm install gsap
gasp官网

代码
<template>
<!-- 这是页面的结构 -->
<div class="box">
<!-- 用于模拟页面中的其他内容,滚动条可用来查看整个动画效果 -->
<div style="height: 100vh; background-color: red">14</div>
<!-- 这是 logo 部分,包含三个文字元素 -->
<div ref="logo" class="preview center">
<div class="logo-text-1">去</div>
<div class="logo-text-1">哪</div> <!-- logo 的第一部分文字 -->
<div class="logo-text-2">旅</div> <!-- logo 的第二部分文字 -->
<div class="logo-text-3">行</div> <!-- logo 的第三部分文字 -->
</div>
</div>
</template>
<script setup>
import gsap from 'gsap';
import { ScrollTrigger } from "gsap/ScrollTrigger";
gsap.registerPlugin(ScrollTrigger);
import { onMounted, ref } from "vue";
onMounted(() => {
animation();
});
const logo = ref(null);
function animation() {
gsap.fromTo(logo.value,
{
fontSize: '10vw',
color: '#ffff',
textAlign: 'center',
},
{
duration: 4,
ease: 'power1',
fontSize: '28vw',
color: 'transparent',
scrollTrigger: {
trigger: logo.value,
scrub: true,
pin: true,
start: 'top center',
end: 'bottom top'
}
}
);
}
</script>
<style scoped>
.box {
background-color: #c36ed9;
height: 5000px;
overflow: hidden;
}
.logo-text-1 {
background: url("assets/site_1.jpeg") no-repeat center/cover;
background-clip: text;
font-weight: bold;
}
.logo-text-2 {
background: url("assets/site_2.jpg") no-repeat center/cover;
background-clip: text;
font-weight: bold;
}
.logo-text-3 {
background: url("assets/site_3.jpg") no-repeat center/cover;
background-clip: text;
font-weight: bold;
}
.center {
display: flex;
justify-content: center;
align-items: center;
}
</style>