Zach Saucier
Front-end web developer; specialist in web animations and user interaction.
gsap.fromTo(".box", {x: 0}, { duration: 1, x: 100 });
gsap.to(".box", { duration: 1, x: 100 });
gsap.from(".box", { duration: 1, x: 100 });
gsap.fromTo(".box", { x: 50 }, { duration: 1, x: 100 });
gsap.to(".box", { duration: 1, x: "+=50" });
gsap.from(".box", { duration: 1, x: "-=100vw" });
gsap.to(".box", { duration: 1, xPercent: 50 });
const tl = gsap.timeline();
tl.to(".box", { duration: 1, x: 100 })
.to(".box", { duration: 1, backgroundColor: "#f38630" }, "+=0.5")
.to(".box", { duration: 1, x: 0, rotation: -360 }, "+=0.5")
gsap.to(".box", { duration: 1, x: 100 });
gsap.to(".box", { duration: 1, backgroundColor: "#f38630", delay: 1.5 };
gsap.to(".box", { duration: 1, x: 0, rotation: -360, delay: 3 };
const tl = gsap.timeline({ defaults: { duration: 1 } });
tl.to(".box", { x: 100 })
.to(".box", { backgroundColor: "#f38630" }, "+=0.5")
.to(".box", { x: 0, rotation: -360 }, "+=0.5")
gsap.to(".box", {
defaults: { duration: 1 },
keyframes: [
{ x: 100 },
{ backgroundColor: "#f38630", delay: 0.5 },
{ x: 0, rotation: -360, delay: 0.5 }
]
});
Allow you to scrub through and go through part of an animation (multiple states).
box.addEventListener("click", e => {
gsap.to(box, { x: 100 });
});
const anim = gsap.to(box, { x: 100, paused: true });
box.addEventListener("click", e => anim.restart() );
gsap.to(".box, .circle", { ... });
gsap.to([box, circle], { ... });
stagger: {
amount: 1.5,
from: targetElem,
grid: 'auto'
}
stagger: 0.1,
const colors = ["#3498db", "#27ae60", "#f1c40f"];
// In your tween
backgroundColor: i => colors[i % 3]
y: (i, target, targets) => i % 2 === 1 ? -yMove : yMove
elems.forEach(elem => {
// Scope variables
let info = container.querySelector(".information"),
silhouette = container.querySelector(".silhouette .cover"),
tl = gsap.timeline({ paused: true });
// Animation specific to element(s)
tl.to(info, { yPercent: 0 })
.to(silhouette, { opacity: 0 }, 0);
// Add event listeners
container.addEventListener("mouseenter", () => tl.play() );
container.addEventListener("mouseleave", () => tl.reverse() );
});
elems.forEach(elem => {
// Scope variables
let info = container.querySelector(".information"),
silhouette = container.querySelector(".silhouette .cover"),
tl = gsap.timeline({ paused: true });
// Animation specific to element(s)
tl.to(info, { yPercent: 0 })
.to(silhouette, { opacity: 0 }, 0);
// Add event listeners
container.addEventListener("mouseenter", () => tl.play() );
container.addEventListener("mouseleave", () => tl.reverse() );
});
function doAnimation() {
const tl = gsap.timeline();
tl.to(...);
tl.to(...);
// ...as many animations as you’d like!
// When you’re all done, return the timeline
return tl;
}
const master = gsap.timeline();
master.add( doAnimation() );
master.add( doAnotherAnimation() );
// register the effect with GSAP:
gsap.registerEffect({
name: "fade",
defaults: {duration: 2}, //defaults get applied to the "config" object passed to the effect below
effect: (targets, config) => {
return gsap.to(targets, {duration: config.duration, opacity:0});
}
});
// now we can use it like this:
gsap.effects.fade(".box");
// Or override the defaults:
gsap.effects.fade(".box", {duration: 1});
By Zach Saucier
For JSDays conference on October 14, 2020.
Front-end web developer; specialist in web animations and user interaction.