Capítulo 148 de 411

Chapter 148: gsap.utils.wrap()

Core Idea

wrap() places a number (or array index) into a range so it cycles back to the start when it exceeds the maximum, and to the end when it goes below the minimum.

Reference Tables

SignatureDescription
wrap(min, max, valueToWrap) | wrap(array, index)returns the wrapped value/element immediately
wrap(min, max) | wrap(array)returns a reusable wrapping function

Code Examples

gsap.utils.wrap(["red", "green", "yellow"], 5); // "yellow" (index 5 wraps to 2)
  • What it demonstrates: cycling through a 3-color array as the index grows past its length, e.g. for repeating stagger colors across many elements.

Connects To

  • gsap.utils.wrapYoyo(): same idea but bounces back and forth instead of wrapping around.