Returns : *
Returns a clamped number between the given maximum and minimum. Returns a function that returns a number if no value (third parameter) is given.
Given a minimum and maximum, clamp the given value
(3rd parameter) such that it’s in the range. If you don’t provide a value
to clamp, it’ll return a function
that’s ready to do the clamping accordingly.
// clamps a value to a certain minimum and maximum. Parameters are: minimum, maximum, value
let num = gsap.utils.clamp(0, 100, 105); // 100
let num = gsap.utils.clamp(0, 100, -50); // 0
let num = gsap.utils.clamp(0, 100, 20); // 20
//if we don't provide a value to clamp (3rd parameter), we get back a function that's ready to do the clamping accordingly
let clamper = gsap.utils.clamp(0, 100); // <- function!
//now we can feed a value into the function we got from the line above and it'll perform clamping accordingly:
let num = clamper(-10); //0