Code

GSAP

Timeline

Beginnergsap.timeline() sequences tweens in order, overlaps them with position parameters (<, -=, labels), and applies shared defaults. GSAP Docs

const tl = gsap.timeline({
  repeat: -1, yoyo: true,
  defaults: { ease: 'power1.inOut' }
});

tl
  // plays after previous ends
  .to(box, { x: 200, duration: 0.8 })
  // starts 0.1s after previous ends
  .to(box, { y: 60, duration: 0.6 }, '+=0.1')
  // starts 0.2s into previous tween
  .to(box, {
    rotation: 360, scale: 1.3,
    duration: 0.7
  }, '<0.2')
  // 0.4s before end of timeline
  .to(trail, {
    scaleX: 1.6, opacity: 0.6,
    duration: 0.5
  }, '-=0.4')
  // label 'step2' as a bookmark
  .to(dot, {
    x: 200, backgroundColor: '#ef4444',
    duration: 0.9
  }, 'step2')
  .to(box, {
    scale: 1, rotation: 0,
    duration: 0.4
  }, 'step2+=0.2');