Capítulo 144 de 411

Chapter 144: gsap.utils.snap()

Core Idea

snap() snaps a value to the closest multiple of an increment, or to the closest value in an array (optionally scoped to a radius, including 2D {x, y} points).

Reference Tables

SignatureDescription
snap(increment, valueToSnap)returns the snapped value immediately
snap(increment)returns a reusable function

Code Examples

gsap.utils.snap(5, 13); // 15
gsap.utils.snap([0, 50, 150, 500], 42); // 50

Connects To

  • snap (tween property, Core Plugin): the tween-integrated version of the same logic.