GSAP 3 Express Notes
GSAP 3 Express Notes
So glad you signed up for this course. I think you’re really going to like what I have to show you.
I know you can learn a lot just from watching the videos but I really want you to get your hands
dirty.
This document contains some top-level notes and brief instructions for some practice exercises.
I urge you to type as much as possible and NOT copy and paste code. You will need to know
how to type this stuff and taking the time to do it right at the beginning will pay off.
Also, coding is about experimentation and play. Please tweak the code, play with the values,
add extra properties and see what happens! Everything here is just provided as a starting point.
If you have any questions about the course just add a comment in the course community
section.
This is the first release of this course, so please forgive any errors or hiccups. If you see
something that needs fixing please let me know. carl@snorkl.tv
Happy Animating!
Carl
After watching the GSAP + CodePen video please follow the steps below to create a basic
GSAP demo with a run button.
Basic Tween
Create a tween using the gsap.to() method.
If you do not specify a duration, gsap will use the default which is 0.5 seconds (500ms).
gsap.defaults({
duration: 1
});
Behind the scenes gsap changes the target’s inline style during the animation.
1. x
2. y
3. rotation
4. rotationX
5. rotationY
6. skewX and skewY
7. scaleX, scaleY, or just scale
Changing values that are not CSS Transforms or opacity can cause the browser to re-do its
layout of the page which in extreme situations can hinder performance. For a few tweens, it’s
not the end of the world as some purists make it out to be.
1: Open: https://codepen.io/snorkltv/pen/qBBxPme
gsap.fromTo() animates from the values you specify to the values you specify.
For best results make sure the from vars and to vars have the same properties.
fromTo() Exercise
1: Open: https://codepen.io/snorkltv/pen/qBBxPme
gsap.fromTo(".fred",
{x:700, y:400, opacity:0},
{x:400, y:200, scale:3,
opacity:1, duration:3});
Practice
1: Open: https://codepen.io/snorkltv/pen/qBBxPme
In simple uses an ease will control whether your animation slows down or speeds up.
An ease can be applied on the way out (default), on the way in, or both directions.
In GSAP3 you no longer need the staggerTo(), staggerFrom(), and staggerFromTo() methods of
GSAP2.
// each image will start 0.2 seconds after the previous one starts.
gsap.to("#freds img", {y:-100, stagger:0.2});
A stagger object gives you greater control over where the staggers start from and how the
timing is dispersed.
each:0.2 means there will be 0.2 seconds between the start of each animation.
amount:0.2 means all animations will start within 0.2 seconds.
Practice
Tween Control
Tween’s have a number of methods for controlling playback.
To prevent a tween from playing automatically you can set its paused special property to true.
tween.play();
Practice
GSAP Docs
Visit the GSAP Docs https://greensock.com/docs/v3/GSAP/Tween and be sure to bookmark
them! Study the methods and properties of the GSAP object and Tween class.
Basic Timeline
A timeline is created with gsap.timeline();
All tweens in a timeline naturally play one after the other.
Practice
gsap.timeline()
.from("#demo", {autoAlpha:0})
.from("#title", {opacity:0, scale:0, ease:"back"})
.from("#freds img", {y:160, stagger:0.1, duration:0.8,
ease:"back"})
.from("#time", {xPercent:100, duration:0.2})
3: SAVE the pen so you can use it in the next practice session (you need to have a FREE
CodePen account in order to save).
Position Parameter
The position parameter allows you to offset the start time of tweens in a timeline.
Challenge
Using the file from the previous lesson:
Practice
2: Add the following code ( I suggest typing it line-by-line and running it often so you can see
which each line does)
3: Save the demo so that you can continue working on it in future lessons.
Final Project Timeline Defaults
Timeline defaults allow us to apply the same property values to every tween in a timeline.
Practice
1: Open the demo you were working on in the last practice session.
2: Remove all instances of opacity:0 from the code as shown below in red (and commas too).
var tl = gsap.timeline()
tl.from("#demo", {opacity:0})
.from("h1", {x:80, opacity:0})
.from("h2", {x:-80, opacity:0})
.from("p", {y:30, opacity:0})
.from("button", {y:50, opacity:0})
.from("#items > g", {
transformOrigin:"50% 50%",
scale:0,
opacity:0,
stagger:0.1,
})
tl.from("#demo", {ease:"linear"})
GSDevTools is bonus tool for Club GreenSock members, but you can use it for free on
CodePen.
Read about GSDevTools: https://greensock.com/gsdevtools
Get CodePen-friendly urls for all Club GreenSock plugins:
https://codepen.io/GreenSock/full/23d3979528b262cb07da37f6a7c7dd76
Practice
1: return to your demo from the previous practice session
2: add code following code below your timeline code:
GSDevTools.create();
Practice
In order to give users the quickest loading experience its recommended to load your custom
scripts after the closing body tag. For our purposes we are using GSAP to animate things in
from an opacity of 0, however there is always going to be a brief duration of time after the page
is rendered and your JavaScript runs; this is the flash of unstyled content.
1. Hide the <div> that contains all your elements by giving it a css style of visibility:hidden
2. Create gsap animation code that fades in from autoAlpha:0
3. Wrap your animation code in an init function().
4. Call the init function after the page loads using a load event listener
Practice
Credits:
vector artwork for final project from:
https://www.freepik.com/free-vector/gradient-creative-landing-page_5289087.htm#page=1&quer
y=landing%20page&position=17