<div class="space">gsap 기본 예제</div>
<section class="section1">
gsap.to()
<div class="box1">box1</div>
</section>
<section class="section2">
gsap.timeline().to()
<div class="box2">box2</div>
</section>
<div class="space">gsap</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.4/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.4/ScrollTrigger.min.js"></script>
.space {
display: flex;
justify-content: center;
align-items: center;
height: 50vh;
font-size: 3rem;
font-weight: bold;
}
.section1 {
display: flex;
flex-direction: column;
align-items: center;
gap: 40px;
height: 100vh;
background-color: lightblue;
}
.box1 {
width: 200px;
height: 200px;
background: lightcoral;
}
.section2 {
display: flex;
flex-direction: column;
align-items: center;
gap: 40px;
height: 100vh;
background-color: lightpink;
}
.box2 {
width: 200px;
height: 200px;
background: red;
border-radius: 50%;
}
gsap.registerPlugin(ScrollTrigger);
gsap.to(".box1", {
x: 400,
y: 400,
backgroundColor: "blue",
duration: 2,
scrollTrigger: {
trigger: ".section1",
start: "0 30%",
end: "100% 60%",
scrub: true,
},
});
const tl = gsap.timeline({
scrollTrigger: {
trigger: ".section2",
start: "0 0",
end: "+=400",
scrub: 0.7,
markers: true,
pin: true,
},
});
tl.to(".box2", {
y: 200,
duration: 2,
})
.to(".box2", {
x: 200,
duration: 2,
})
.to(".box2", {
rotation: 45,
scale: 2,
});