vael-ui v0.5.7

Motion

mapRange

Turns one number into another by lining up two ranges: a drag's offset into a tilt, a scroll into an opacity. Pair it with a live value in v-animate.

Maps a number from one range onto another. mapRange(x, [0, 300], [0, 1]) gives 0 at 0, 0.5 at 150 and 1 at 300. Past either end it holds the end value. Add points to bend the line: mapRange(x, [-300, 0, 300], [-20, 0, 20]). Use it with a live value in v-animate.

Install

import { mapRange } from 'vael-ui/motion'

Examples

Parameters

NameTypeDescription
valuenumberThe number to turn into another: an offset, a scroll position, a slider value.
fromnumber[]Points along the range it comes from, in increasing order: [0, 300], or more to bend the line.
tonumber[]What each of those points becomes: to[i] for from[i]. Between two points it moves in a straight line.

Returns

NameTypeDescription
resultnumberThe number in the new range. Below the first point it’s to[0], above the last it’s the last of to.