Code icon

The App is Under a Quick Maintenance

We apologize for the inconvenience. Please come back later

Menu iconMenu iconFundamentos de Animación Web con GSAP: Construye y Diseña Impresionantes Sitios Web Interactivos con JavaScript
Fundamentos de Animación Web con GSAP: Construye y Diseña Impresionantes Sitios Web Interactivos con JavaScript

Chapter 2: Getting Started with GSAP

Practical Exercises for Chapter 2: Getting Started with GSAP

Fantastic work on completing Chapter 2! To solidify your understanding and skills in GSAP, here are some practical exercises. Each exercise is designed to challenge you while reinforcing the concepts learned in this chapter. Solutions are provided to guide you, but I encourage you to try solving them on your own first. Remember, experimentation is key to mastering GSAP!

Exercise 1: Animate a Sequence of Elements

Create an animation sequence where three different elements (divs) move across the screen one after the other, not simultaneously.

Solution:
HTML:

<div class="sequence" id="elem1"></div>
<div class="sequence" id="elem2"></div>
<div class="sequence" id="elem3"></div>

CSS:

.sequence {
    width: 50px;
    height: 50px;
    background-color: blue;
    position: relative;
    margin: 10px;
}

JavaScript:

let tl = gsap.timeline();
tl.to("#elem1", {duration: 1, x: 100})
  .to("#elem2", {duration: 1, x: 100})
  .to("#elem3", {duration: 1, x: 100});

Exercise 2: Create a Looping Animation

Make an element rotate 360 degrees continuously in a loop.

Solution:
HTML:

<div id="loopingElement"></div>

CSS:

#loopingElement {
    width: 100px;
    height: 100px;
    background-color: green;
    position: relative;
}

JavaScript:

gsap.to("#loopingElement", {duration: 2, rotation: 360, repeat: -1, ease: "none"});

Exercise 3: Building an Animated Landing Page Banner

Create a landing page banner where multiple elements (text, images, shapes) come in from different directions, creating an engaging intro animation.

Solution:
HTML:

<div id="banner">
    <h1 id="title">Welcome!</h1>
    <img id="image" src="path/to/image.jpg" alt="Banner Image">
    <p id="description">Your description here.</p>
</div>

CSS:

#banner {
    position: relative;
    width: 100%;
    height: 300px;
    background-color: #eee;
}
#title, #image, #description {
    position: absolute;
    opacity: 0;
}

JavaScript:

let bannerTl = gsap.timeline();
bannerTl.from("#title", {duration: 1, x: -200, opacity: 1})
        .from("#image", {duration: 1, y: -200, opacity: 1}, "-=0.5")
        .from("#description", {duration: 1, x: 200, opacity: 1}, "-=0.5");

Exercise 4: Staggered Entrance of a List

Animate a list of items so that they appear one after another with a slight delay between each, creating a staggered entrance effect.

Solution:
HTML:

<ul id="myList">
    <li class="item">Item 1</li>
    <li class="item">Item 2</li>
    <li class="item">Item 3</li>
</ul>

CSS:

.item {
    opacity: 0;
    transform: translateX(-50px);
}

JavaScript:

gsap.to(".item", {duration: 1, opacity: 1, x: 0, stagger: 0.2});

These exercises are designed to give you a hands-on experience in creating a variety of animations with GSAP. By working through these challenges, you will gain a deeper understanding of how GSAP functions and how to apply its features creatively. Remember, the key to mastering GSAP is practice and experimentation. So, feel free to modify these exercises, experiment with different animations, and see what amazing creations you can come up with!

Practical Exercises for Chapter 2: Getting Started with GSAP

Fantastic work on completing Chapter 2! To solidify your understanding and skills in GSAP, here are some practical exercises. Each exercise is designed to challenge you while reinforcing the concepts learned in this chapter. Solutions are provided to guide you, but I encourage you to try solving them on your own first. Remember, experimentation is key to mastering GSAP!

Exercise 1: Animate a Sequence of Elements

Create an animation sequence where three different elements (divs) move across the screen one after the other, not simultaneously.

Solution:
HTML:

<div class="sequence" id="elem1"></div>
<div class="sequence" id="elem2"></div>
<div class="sequence" id="elem3"></div>

CSS:

.sequence {
    width: 50px;
    height: 50px;
    background-color: blue;
    position: relative;
    margin: 10px;
}

JavaScript:

let tl = gsap.timeline();
tl.to("#elem1", {duration: 1, x: 100})
  .to("#elem2", {duration: 1, x: 100})
  .to("#elem3", {duration: 1, x: 100});

Exercise 2: Create a Looping Animation

Make an element rotate 360 degrees continuously in a loop.

Solution:
HTML:

<div id="loopingElement"></div>

CSS:

#loopingElement {
    width: 100px;
    height: 100px;
    background-color: green;
    position: relative;
}

JavaScript:

gsap.to("#loopingElement", {duration: 2, rotation: 360, repeat: -1, ease: "none"});

Exercise 3: Building an Animated Landing Page Banner

Create a landing page banner where multiple elements (text, images, shapes) come in from different directions, creating an engaging intro animation.

Solution:
HTML:

<div id="banner">
    <h1 id="title">Welcome!</h1>
    <img id="image" src="path/to/image.jpg" alt="Banner Image">
    <p id="description">Your description here.</p>
</div>

CSS:

#banner {
    position: relative;
    width: 100%;
    height: 300px;
    background-color: #eee;
}
#title, #image, #description {
    position: absolute;
    opacity: 0;
}

JavaScript:

let bannerTl = gsap.timeline();
bannerTl.from("#title", {duration: 1, x: -200, opacity: 1})
        .from("#image", {duration: 1, y: -200, opacity: 1}, "-=0.5")
        .from("#description", {duration: 1, x: 200, opacity: 1}, "-=0.5");

Exercise 4: Staggered Entrance of a List

Animate a list of items so that they appear one after another with a slight delay between each, creating a staggered entrance effect.

Solution:
HTML:

<ul id="myList">
    <li class="item">Item 1</li>
    <li class="item">Item 2</li>
    <li class="item">Item 3</li>
</ul>

CSS:

.item {
    opacity: 0;
    transform: translateX(-50px);
}

JavaScript:

gsap.to(".item", {duration: 1, opacity: 1, x: 0, stagger: 0.2});

These exercises are designed to give you a hands-on experience in creating a variety of animations with GSAP. By working through these challenges, you will gain a deeper understanding of how GSAP functions and how to apply its features creatively. Remember, the key to mastering GSAP is practice and experimentation. So, feel free to modify these exercises, experiment with different animations, and see what amazing creations you can come up with!

Practical Exercises for Chapter 2: Getting Started with GSAP

Fantastic work on completing Chapter 2! To solidify your understanding and skills in GSAP, here are some practical exercises. Each exercise is designed to challenge you while reinforcing the concepts learned in this chapter. Solutions are provided to guide you, but I encourage you to try solving them on your own first. Remember, experimentation is key to mastering GSAP!

Exercise 1: Animate a Sequence of Elements

Create an animation sequence where three different elements (divs) move across the screen one after the other, not simultaneously.

Solution:
HTML:

<div class="sequence" id="elem1"></div>
<div class="sequence" id="elem2"></div>
<div class="sequence" id="elem3"></div>

CSS:

.sequence {
    width: 50px;
    height: 50px;
    background-color: blue;
    position: relative;
    margin: 10px;
}

JavaScript:

let tl = gsap.timeline();
tl.to("#elem1", {duration: 1, x: 100})
  .to("#elem2", {duration: 1, x: 100})
  .to("#elem3", {duration: 1, x: 100});

Exercise 2: Create a Looping Animation

Make an element rotate 360 degrees continuously in a loop.

Solution:
HTML:

<div id="loopingElement"></div>

CSS:

#loopingElement {
    width: 100px;
    height: 100px;
    background-color: green;
    position: relative;
}

JavaScript:

gsap.to("#loopingElement", {duration: 2, rotation: 360, repeat: -1, ease: "none"});

Exercise 3: Building an Animated Landing Page Banner

Create a landing page banner where multiple elements (text, images, shapes) come in from different directions, creating an engaging intro animation.

Solution:
HTML:

<div id="banner">
    <h1 id="title">Welcome!</h1>
    <img id="image" src="path/to/image.jpg" alt="Banner Image">
    <p id="description">Your description here.</p>
</div>

CSS:

#banner {
    position: relative;
    width: 100%;
    height: 300px;
    background-color: #eee;
}
#title, #image, #description {
    position: absolute;
    opacity: 0;
}

JavaScript:

let bannerTl = gsap.timeline();
bannerTl.from("#title", {duration: 1, x: -200, opacity: 1})
        .from("#image", {duration: 1, y: -200, opacity: 1}, "-=0.5")
        .from("#description", {duration: 1, x: 200, opacity: 1}, "-=0.5");

Exercise 4: Staggered Entrance of a List

Animate a list of items so that they appear one after another with a slight delay between each, creating a staggered entrance effect.

Solution:
HTML:

<ul id="myList">
    <li class="item">Item 1</li>
    <li class="item">Item 2</li>
    <li class="item">Item 3</li>
</ul>

CSS:

.item {
    opacity: 0;
    transform: translateX(-50px);
}

JavaScript:

gsap.to(".item", {duration: 1, opacity: 1, x: 0, stagger: 0.2});

These exercises are designed to give you a hands-on experience in creating a variety of animations with GSAP. By working through these challenges, you will gain a deeper understanding of how GSAP functions and how to apply its features creatively. Remember, the key to mastering GSAP is practice and experimentation. So, feel free to modify these exercises, experiment with different animations, and see what amazing creations you can come up with!

Practical Exercises for Chapter 2: Getting Started with GSAP

Fantastic work on completing Chapter 2! To solidify your understanding and skills in GSAP, here are some practical exercises. Each exercise is designed to challenge you while reinforcing the concepts learned in this chapter. Solutions are provided to guide you, but I encourage you to try solving them on your own first. Remember, experimentation is key to mastering GSAP!

Exercise 1: Animate a Sequence of Elements

Create an animation sequence where three different elements (divs) move across the screen one after the other, not simultaneously.

Solution:
HTML:

<div class="sequence" id="elem1"></div>
<div class="sequence" id="elem2"></div>
<div class="sequence" id="elem3"></div>

CSS:

.sequence {
    width: 50px;
    height: 50px;
    background-color: blue;
    position: relative;
    margin: 10px;
}

JavaScript:

let tl = gsap.timeline();
tl.to("#elem1", {duration: 1, x: 100})
  .to("#elem2", {duration: 1, x: 100})
  .to("#elem3", {duration: 1, x: 100});

Exercise 2: Create a Looping Animation

Make an element rotate 360 degrees continuously in a loop.

Solution:
HTML:

<div id="loopingElement"></div>

CSS:

#loopingElement {
    width: 100px;
    height: 100px;
    background-color: green;
    position: relative;
}

JavaScript:

gsap.to("#loopingElement", {duration: 2, rotation: 360, repeat: -1, ease: "none"});

Exercise 3: Building an Animated Landing Page Banner

Create a landing page banner where multiple elements (text, images, shapes) come in from different directions, creating an engaging intro animation.

Solution:
HTML:

<div id="banner">
    <h1 id="title">Welcome!</h1>
    <img id="image" src="path/to/image.jpg" alt="Banner Image">
    <p id="description">Your description here.</p>
</div>

CSS:

#banner {
    position: relative;
    width: 100%;
    height: 300px;
    background-color: #eee;
}
#title, #image, #description {
    position: absolute;
    opacity: 0;
}

JavaScript:

let bannerTl = gsap.timeline();
bannerTl.from("#title", {duration: 1, x: -200, opacity: 1})
        .from("#image", {duration: 1, y: -200, opacity: 1}, "-=0.5")
        .from("#description", {duration: 1, x: 200, opacity: 1}, "-=0.5");

Exercise 4: Staggered Entrance of a List

Animate a list of items so that they appear one after another with a slight delay between each, creating a staggered entrance effect.

Solution:
HTML:

<ul id="myList">
    <li class="item">Item 1</li>
    <li class="item">Item 2</li>
    <li class="item">Item 3</li>
</ul>

CSS:

.item {
    opacity: 0;
    transform: translateX(-50px);
}

JavaScript:

gsap.to(".item", {duration: 1, opacity: 1, x: 0, stagger: 0.2});

These exercises are designed to give you a hands-on experience in creating a variety of animations with GSAP. By working through these challenges, you will gain a deeper understanding of how GSAP functions and how to apply its features creatively. Remember, the key to mastering GSAP is practice and experimentation. So, feel free to modify these exercises, experiment with different animations, and see what amazing creations you can come up with!