Jump to content
GreenSock

GreenSock Docs

mapRange()

Returns : *

Returns a number mapped from one range to another. Returns a function that returns mapped numbers if no value (fifth parameter) is given.


Maps a value from one range to another range.

For example, if you have values between -10 and 10 and you want to map them to a range from 0 to 100, so that feeding in 0 would return 50, it’s simple.

If you don’t provide a value (5th parameter) to map, it’ll return a function that’s ready to perform mapping accordingly.

  1. //maps 0 in the -10 to 10 range to the same position in the 100 to 200 range
  2. let num = gsap.utils.mapRange(-10, 10, 100, 200, 0); //150
  3. //if we don't provide a value to map, we get a function that's ready to perform mapping accordingly
  4. let mapper = gsap.utils.mapRange(-10, 10, 100, 200); // <- function!
  5. //now we just feed any number into the function we got in the line above, and it'll return the mapped value
  6. let num = mapper(0); //150
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.
×