Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...

GreenSock Docs

clamp()

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.

  1. // clamps a value to a certain minimum and maximum. Parameters are: minimum, maximum, value
  2. let num = gsap.utils.clamp(0, 100, 105); // 100
  3. let num = gsap.utils.clamp(0, 100, -50); // 0
  4. let num = gsap.utils.clamp(0, 100, 20); // 20
  5. //if we don't provide a value to clamp (3rd parameter), we get back a function that's ready to do the clamping accordingly
  6. let clamper = gsap.utils.clamp(0, 100); // <- function!
  7. //now we can feed a value into the function we got from the line above and it'll perform clamping accordingly:
  8. let num = clamper(-10); //0
Copyright 2017, GreenSock. All rights reserved. This work is subject to theterms of useor for Club GreenSock members, the software agreement that was issued with the membership.
×