Skip to article

mapValue

mapValue() maps a motion value's output range to numbers, colours, or complex strings.

mapValue creates a new read-only motion value that maps the output of a numerical motion value to a range of numbers, colors or complex strings.

const x = motionValue(100)

// Fade out outside the 0-100 range
const opacity = mapValue(x, [-100, 0, 100, 200], [0, 1, 1, 0])

// Shift color when fading out
const backgroundColor = mapValue(opacity, [0, 1], ["#f00", "#00f"])
Image reveal sliderOpen example

Usage

Import mapValue from