Post

웹페이지를 더 동적으로! GSAP을 활용한 페이지 스크롤 애니메이션

💡GSAP를 활용하여 멋진 스크롤 애니메이션을 만들어 봅시다

💡01: 이미지 애니메이션 주기

1
2
3
4
<section id="section01">
    <span class="num">01</span>
    <div class="img"></div>
</section>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const ani1 = gsap.timeline();

ani1.to("#section01 .img", { rotation: 720, scale: 0, borderRadius: 200 })
    .to("#section01 .img", { rotation: 0, scale: 1, borderRadius: 20 })

ScrollTrigger.create({
    animation: ani1,
    trigger: "#section01",
    start: "top top",
    end: "+=2000",
    scrub: true,
    pin: true,
    anticipatePin: 1,
    markers: true
});

1.HTML에서는 이미지를 포함하는 <section> 요소에 id를 부여합니다.
2.GSAP의 timeline() 메서드를 사용하여 애니메이션 타임라인을 생성합니다.
3.to() 메서드를 사용하여 이미지를 회전하고 크기를 조절하는 애니메이션을 정의합니다.
4.ScrollTrigger.create()를 사용하여 스크롤 트리거를 생성합니다.
5.animation: 위에서 정의한 애니메이션을 할당합니다.
6.trigger: 애니메이션이 시작될 지점을 지정합니다.
7.start: 애니메이션을 시작할 스크롤 위치를 설정합니다.
8.end: 애니메이션의 끝나는 지점을 설정합니다.
9.scrub: 스크롤 중에 애니메이션을 스크럽할지 여부를 설정합니다.
10.pin: 애니메이션이 트리거 영역에 고정될지 여부를 설정합니다.
11.anticipatePin: 애니메이션이 고정될 때 약간의 여유를 두는 시간을 설정합니다.
12.markers: 디버깅 및 시각적 확인을 위해 트리거를 표시할지 여부를 설정합니다.

💡02: 이미지 순차적으로 나오기

1
2
3
4
5
6
7
<section id="section02">
    <span class="num">02</span>
    <div class="img i1"></div>
    <div class="img i2"></div>
    <div class="img i3"></div>
    <div class="img i4"></div>
</section>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const ani2 = gsap.timeline();

ani2.from("#section02 .i1", { y: -100, autoAlpha: 0, borderRadius: 200 }, "a")
    .from("#section02 .i2", { y: 100, autoAlpha: 0, borderRadius: 200 }, "b")
    .from("#section02 .i3", { y: -100, autoAlpha: 0, borderRadius: 200 }, "a")
    .from("#section02 .i4", { y: -100, autoAlpha: 0, borderRadius: 200 }, "b")

ScrollTrigger.create({
    animation: ani2,
    trigger: "#section02",
    start: "top top",
    end: "+=2000",
    scrub: true,
    pin: true,
    anticipatePin: 1,
    markers: true
});

1.HTML에서는 여러 이미지를 포함하는 <section> 요소에 id를 부여합니다.
2.timeline() 메서드를 사용하여 애니메이션 타임라인을 생성합니다.
3.from() 메서드를 사용하여 각 이미지가 순차적으로 나타나는 애니메이션을 정의합니다.
4.ScrollTrigger를 생성하여 페이지 스크롤과 애니메이션을 연결합니다.

💡03: 이미지 랜덤으로 나오기

1
2
3
4
5
6
7
8
9
10
<section id="section03">
    <span class="num">03</span>
    <div class="img i1"></div>
    <div class="img i2"></div>
    <div class="img i3"></div>
    <div class="img i4"></div>
    <div class="img i5"></div>
    <div class="img i6"></div>
    <div class="img i7"></div>
</section>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const ani3 = gsap.timeline();

ani3.from("#section03 .img", {
    y: -100,
    autoAlpha: 0,
    borderRadius: 200,
    scale: 0.5,
    ease: "power4.out",
    stagger: {
        amount: 3,
        from: "random"
    }
});

ScrollTrigger.create({
    animation: ani3,
    trigger: "#section03",
    start: "top top",
    end: "+=3000",
    scrub: true,
    pin: true,
    anticipatePin: 1,
    markers: true
});

1.HTML에서는 여러 이미지를 포함하는 <section> 요소에 id를 부여합니다.
2.timeline() 메서드를 사용하여 애니메이션 타임라인을 생성합니다.
3.from() 메서드를 사용하여 각 이미지가 나타나는 애니메이션을 정의합니다.
4.stagger 옵션을 사용하여 이미지들이 순차적으로 나타나도록 설정합니다. amount는 각 요소 사이의 간격을 지정하고, from: “random”은 랜덤한 순서로 요소들이 나타나도록 합니다.
5.ScrollTrigger를 생성하여 페이지 스크롤과 애니메이션을 연결합니다.

💡04: 이미지 축소

1
2
3
4
 <section id="section04">
    <span class="num">04</span>
    <div class="img"></div>
</section>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const ani4 = gsap.timeline();
ani4.from("#section04 .img", {
    autoAlpha: 0,
    scale: 5,
    width: "100vw",
    height: "100vh"
});

ScrollTrigger.create({
    animation: ani4,
    trigger: "#section04",
    start: "top top",
    end: "+=3000",
    scrub: true,
    pin: true,
    anticipatePin: 1,
    markers: true
});

1.HTML에서는 이미지를 포함하는 <section> 요소에 id를 부여합니다.
2.timeline() 메서드를 사용하여 애니메이션 타임라인을 생성합니다.
3.from() 메서드를 사용하여 이미지 축소 애니메이션을 정의합니다.
4.scale을 사용하여 이미지를 축소하고, autoAlpha를 0으로 설정하여 투명도를 조절합니다.
5.width와 height를 사용하여 이미지의 크기를 전체 화면으로 확장합니다.
6.ScrollTrigger를 생성하여 페이지 스크롤과 애니메이션을 연결합니다.

💡05: 텍스트 애니메이션

1
2
3
4
5
6
7
<section id="section05">
    <span class="num">05</span>
    <div class="text t1">section5</div>
    <div class="text t2">section5</div>
    <div class="text t3">section5</div>
    <div class="text t4">section5</div>
</section>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const ani5 = gsap.timeline();
ani5.to("#section05 .t1", { xPercent: 300 }, "text")
    .to("#section05 .t2", { xPercent: -300 }, "text")
    .to("#section05 .t3", { xPercent: 300 }, "text")
    .to("#section05 .t4", { xPercent: -300 }, "text")

ScrollTrigger.create({
    animation: ani5,
    trigger: "#section05",
    start: "top top",
    end: "+=3000",
    scrub: true,
    pin: true,
    anticipatePin: 1,
    markers: true
});

1.HTML에서는 텍스트를 포함하는 <section> 요소에 id를 부여합니다.
2.timeline() 메서드를 사용하여 애니메이션 타임라인을 생성합니다.
3.to() 메서드를 사용하여 텍스트 이동 애니메이션을 정의합니다.
4.각 텍스트 요소가 일정한 간격으로 오른쪽 또는 왼쪽으로 이동합니다.
5.ScrollTrigger를 생성하여 페이지 스크롤과 애니메이션을 연결합니다.

💡06: 텍스트 확대하기

1
2
3
4
<section id="section06">
    <span class="num">06</span>
    <div class="text">section06</div>
</section>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const ani6 = gsap.timeline();
ani6.to("#section06 .text", { scale: 60, duration: 2, rotation: 100, x: -700 })
    .to("#section06 .text", { autoAlpha: 0 })

ScrollTrigger.create({
    animation: ani6,
    trigger: "#section06",
    start: "top top",
    end: "+=4000",
    scrub: true,
    pin: true,
    anticipatePin: 1,
    markers: true
});

1.HTML에서는 텍스트를 포함하는 <section> 요소에 id를 부여합니다.
2.timeline() 메서드를 사용하여 애니메이션 타임라인을 생성합니다.
3.to() 메서드를 사용하여 텍스트 확대 및 투명도 조절 애니메이션을 정의합니다.
4.scale을 사용하여 텍스트를 확대하고, rotation과 x를 사용하여 회전하고 이동시킵니다.
5.autoAlpha를 0으로 설정하여 텍스트를 투명하게 만듭니다.
6.ScrollTrigger를 생성하여 페이지 스크롤과 애니메이션을 연결합니다.

💡07: 텍스트 제자리 애니메이션

1
2
3
4
5
6
7
8
9
10
<section id="section07">
    <span class="num">07</span>
    <div class="text t1">코딩이란?</div>
    <div class="text t2">프로그래밍 코드를</div>
    <div class="text t3">어딘가에</div>
    <div class="text t4">적는 것을 말한다.</div>
    <div class="text t5">코딩은</div>
    <div class="text t6">누구나</div>
    <div class="text t7">할 수있다.</div>
</section>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const ani7 = gsap.timeline();

ani7.from("#section07 .t1", { autoAlpha: 0, duration: 1, y: 50 }, "+=1")
    .from("#section07 .t2", { autoAlpha: 0, duration: 1, y: 50 }, "+=1")
    .from("#section07 .t3", { autoAlpha: 0, duration: 1, y: 50 }, "+=1")
    .from("#section07 .t4", { autoAlpha: 0, duration: 1, y: 50 }, "+=1")
    .from("#section07 .t5", { autoAlpha: 0, duration: 1, y: 50 }, "+=1")
    .from("#section07 .t6", { autoAlpha: 0, duration: 1, y: 50 }, "+=1")
    .from("#section07 .t7", { autoAlpha: 0, duration: 1, y: 50 }, "+=1");

ScrollTrigger.create({
    animation: ani7,
    trigger: "#section07",
    start: "top top",
    end: "+=6000",
    scrub: true,
    pin: true,
    anticipatePin: 1,
    markers: true
});

1.HTML에서는 텍스트를 포함하는 <section> 요소에 id를 부여합니다.
2.autoAlpha: 0: 요소를 처음에 투명하게 만듭니다. autoAlpha는 opacity와 visibility를 함께 조절하여 요소를 투명하게 만드는 GSAP의 기능입니다. 3.duration: 1: 애니메이션의 지속 시간을 1초로 설정합니다.
4.y: 50: 요소가 위쪽으로 50px만큼 이동합니다. 이것은 애니메이션이 요소를 위쪽으로 이동시키는데 사용됩니다.
5.”+=1”: 애니메이션의 시작 시간을 지연시킵니다. 이것은 이전 애니메이션 이후에 1초 후에 시작되도록 합니다.
6.timeline() 메서드를 사용하여 애니메이션 타임라인을 생성합니다.
7.from() 메서드를 사용하여 텍스트가 제자리에서 나타나는 애니메이션을 정의합니다.
8.각 텍스트가 일정한 간격으로 위쪽으로 이동하며 나타납니다.
9.ScrollTrigger를 생성하여 페이지 스크롤과 애니메이션을 연결합니다.

💡08: 텍스트 애니메이션

1
2
3
4
5
6
7
<section id="section08">
    <span class="num">08</span>
    <div class="text t1">section08</div>
    <div class="text t2">section08</div>
    <div class="text t3">section08</div>
    <div class="img"></div>
</section>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const ani8 = gsap.timeline();

ani8.from("#section08 .t1", { x: innerWidth * 1 })
    .from("#section08 .t2", { x: innerWidth * -1 })
    .from("#section08 .t3", { x: innerWidth * 1 })
    .from("#section08 .img", { x: innerWidth * 1, rotation: 360, scale: 5.5 })

ScrollTrigger.create({
    animation: ani8,
    trigger: "#section08",
    start: "top top",
    end: "+=4000",
    scrub: true,
    pin: true,
    anticipatePin: 1,
    markers: true
});

1.HTML에서는 텍스트와 이미지를 포함하는 <section> 요소에 id를 부여합니다.
2.timeline() 메서드를 사용하여 애니메이션 타임라인을 생성합니다.
3.from() 메서드를 사용하여 각 요소의 애니메이션을 정의합니다.
4.텍스트 요소들은 각각 오른쪽, 왼쪽, 오른쪽에서 등장하도록 설정됩니다.
5.이미지는 오른쪽에서 나타나며, 동시에 360도 회전하고 5.5배 확대됩니다.
6.ScrollTrigger를 생성하여 페이지 스크롤과 애니메이션을 연결합니다.

This post is licensed under CC BY 4.0 by the author.