Capítulo 18 de 411

Chapter 18: gsap.getTweensOf()

Core Idea

gsap.getTweensOf() returns an array of all tweens currently affecting a target (or group of targets) that haven't yet been released for garbage collection.

Key Concepts

  • Returns: an Array of Tween instances.
  • GC boundary: only finds tweens still active/pending; once a tween completes and GSAP releases it, it won't be found anymore.

Code Examples

gsap.to(obj1, { x: 100 });
gsap.to(obj2, { x: 100 });
gsap.to([obj1, obj2], { opacity: 0 });

gsap.getTweensOf(obj1); // 2 tweens
gsap.getTweensOf([obj1, obj2]); // 3 tweens
  • What it demonstrates: how querying by a single target vs. an array of targets returns different tween counts depending on overlap.

Key Takeaways

  1. Useful for inspecting/controlling all in-flight tweens of a target without tracking each one manually.
  2. Like getById(), this only sees animations GSAP hasn't garbage-collected yet — not a permanent registry.

Connects To

  • gsap.getById(): lookup by explicit ID instead of by target.
  • gsap.killTweensOf(): same target-matching logic, used to kill instead of just list.