Capítulo 134 de 411

Chapter 134: gsap.utils.clamp()

Core Idea

clamp() constrains a number to a min/max range — below the minimum returns the minimum, above the maximum returns the maximum, otherwise the number is unchanged.

Reference Tables

SignatureDescription
clamp(min, max, valueToClamp)returns the clamped number immediately
clamp(min, max)returns a reusable function that clamps whatever you feed it later

Code Examples

gsap.utils.clamp(0, 100, 105); // 100

const clampIt = gsap.utils.clamp(0, 100); // reusable
clampIt(105); // 100
  • What it demonstrates: the two call signatures — immediate clamping vs. building a reusable clamper function.

Connects To

  • gsap.utils.pipe(): often chained with clamp() to sanitize a value before further processing.