GSAP์ด๋?
GreenSock Animation Platform
ํ๋ก ํธ์๋ ๊ฐ๋ฐ์์ ๋์์ด๋๋ค์ด ์ฝ๊ฒ ์ฌ์ฉํ ์ ์๋ ์์ฃผ ๊ฐ๋ ฅํ ํ์๋ผ์ธ ๊ธฐ๋ฐ์ ์ ๋๋ฉ์ด์ ์๋ฐ์คํฌ๋ฆฝํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ด๋ค.
GSAP๋ CSS์ keyframe๊ณผ animation ๋ณด๋ค ๋ ์ ๋ฐํ ์ปจํธ๋กค์ ํ ์ ์์ผ๋ฉฐ ๊ฐ๋ณ๊ณ ์ฌ์ฉ๋ฐฉ๋ฒ์ด ์ฝ๋ค๋ ๊ฐ์ฅ ํฐ ์ฅ์ ์ด ์๋ค.
Tween


Tween์ ์ ๋๋ฉ์ด์ ์ ์ ์ํ๋ ๊ฐ์ฒด ๊ฐ๋ ์ด๋ผ๊ณ ๋ณด๋ฉด ๋๋ค.
gsap.to("#b", 3, {delay:2, x:700, repeat:-1});
gsap.from("#g", 3, {delay:2, x:700, repeat:-1});
gsap.fromTo("#r", 3, {x:200}, {delay:2, x:700, repeat:-1})
์ฝ๋์ ๊ฐ๊ฒฐ์ฑ์ ์ํด fromTo method์ ์ฌ์ฉ์ ํผํ๋ ๊ฒ์ด ์ข๋ค.
Timeline

Timeline์ tween ๋ฐ ๊ธฐํ timeline์ ์ปจํ ์ด๋ ์ญํ ์ ํ๋ ๊ฐ๋ ฅํ ์ํ์ฑ ๋๊ตฌ๋ก, ์ ๋๋ฉ์ด์ ์ ํ์ด๋ฐ์ ์ ํํ๊ฒ ๊ด๋ฆฌํ ์ ์๋ค.
ํ์๋ผ์ธ์ ์์ฑ์ tween์ ๋ชจ๋ ๋ํดํธ ์์ฑ๋ค์ overrideํ๋ค.
์ฌ์ฉ๋ฒ์ ์๋ ์ฝ๋์ ๊ฐ๋ค.
let tl = gsap.timeline({
defaults:
{duration: 2, ease: "power1.inOut", yoyo: true, repeat: -1}
})
.to("#cr1", {x: 500})
.to("#cr2", {x: 461.94, y: -191.64}, "<0.25")
.to("#cr3", {x: 353.55, y: -353.56}, "<0.25")
.to("#cr4", {x: 191.34, y: -461.94}, "<0.25")
.to("#cr5", {y: -500}, "<0.25")
.to("#cr6", {x: -191.35, y: -461.94}, "<0.25")
.to("#cr7", {x: -353.55, y: -353.56}, "<0.25")
.to("#cr8", {x: -461.94, y: -191.34}, "<0.25")
document.addEventListener("click", function(e) {
tl.reverse();
});
document.addEventListener("dblclick", function(e) {
tl.play();
});
position parameter
์์ ์ฝ๋์์ "<0.25" ๋ถ๋ถ์ ํด๋นํ๋ ํ๋ผ๋ฏธํฐ์ด๋ค.
๋ชจ๋ tween method์์ ์ฌ์ฉ ๊ฐ๋ฅํ๊ณ , ํ์๋ผ์ธ์์ ์ ๋๋ฉ์ด์ ์ insertion location์ ๊ฒฐ์ ํ๋ค.

position parameter์ absolute time [seconds]๋ก ์์ฑํ๋ค๋ฉด

relative to the end of a timeline [+=seconds / -=seconds] ๋ฐฉ์์ผ๋ก ์์ฑํ๋ค๋ฉด

์ฒซ๋ฒ์งธ ์์ ์ ์ธํ ๋ชจ๋ ์์ด ์ฒ์์ผ๋ก๋ถํฐ 0.25์ด ์ดํ์ ์์ง์ด๊ธฐ ์์ํ๋ ๊ฒ์ด ์๋๋ค.
ํ์๋ผ์ธ์ ์ง์์๊ฐ์ ์ ํ์ง ์์๊ณ , ๊ฐ tween์ ์ง์๊ธฐ๊ฐ์ ๋ํ๋ด๋ ๋ํดํธ ํ๋ผ๋ฏธํฐ๋ฅผ ์ง์ ํ ๊ฒ๋ ์๋๊ธฐ ๋๋ฌธ์,
ํ์๋ผ์ธ์ duration์ ์ ์ง์ ์ผ๋ก ๋์ด๋๊ฒ ๋๋ค.
์ tween์ ๋์์ด ๋๋๋ ์์ ๋ถํฐ 0.25์ด ํ์ ๋์ํ๋ค.
relative to the end of the most recently-added animation [>seconds] ์ ๋ฐฉ์๋ ์ด์ ๊ฐ์ด ๋์ํ๋ค.
relative to the end of the most recently-added animation [>seconds]์ธ๋ฐ seconds ๊ฐ์ ์์๋ก ํ๋ค๋ฉด

relative to the end of a timeline์ธ "-=0.25" ๋ ์ด์ ๋์ผํ๊ฒ ๋์ํ๋ค.

tween์ position parameter์ label ๋ณ์๋ช ์ ๋ฃ์ผ๋ฉด, ํด๋น ๋ผ๋ฒจ ๊ธฐ์ค์ผ๋ก -=, += ํ์ฌ ์๊ฐ์ฐจ๋ฅผ ์ค์ ํ ์ ์๋ค.
control method

์์ ๋ ๋ค์๊ณผ ๊ฐ๋ค.
gsap.registerPlugin(MotionPathPlugin); //path๋ฅผ ๋ฐ๋ผ ์์ง์ด๊ฒ ํ๋ ํ๋ฌ๊ทธ์ธ
let timeline = gsap.timeline({
repeat: 2,
repeatDelay: 5,
defaults: {duration: 12, ease: "power1.inOut"}
})
.to("#hand", {
motionPath: {
path:"#path",
align:"#path",
alignOrigin:[0.28, 0.08]}
})
.to("#path", {strokeDasharray: "4046, " + "0"}, "<");
document.getElementById("pause").onclick = () => timeline.pause();
document.getElementById("play").onclick = () => timeline.play();
document.getElementById("reverse").onclick = () => timeline.reverse();
document.getElementById("seek").onclick = () => timeline.seek(5);
document.getElementById("restart").onclick = () => timeline.restart();