• Transforms numbers into other values by mapping them from an input range to an output range. Returns the type of the input provided.

    Type Parameters

    • T

    Parameters

    • inputValue: number

      A number to transform between the input and output ranges.

    • inputRange: number[]

      A linear series of numbers (either all increasing or decreasing).

    • outputRange: T[]

      A series of numbers, colors, strings, or arrays/objects of those. Must be the same length as inputRange.

    • Optional options: TransformOptions<T>

      Clamp: Clamp values to within the given range. Defaults to true.

    Returns T

    Remarks

    Given an input range of [0, 200] and an output range of [0, 1], this function will return a value between 0 and 1. The input range must be a linear series of numbers. The output range can be any supported value type, such as numbers, colors, shadows, arrays, objects and more. Every value in the output range must be of the same type and in the same format.

    import * as React from "react"
    import { transform } from "framer-motion"

    export function MyComponent() {
    const inputRange = [0, 200]
    const outputRange = [0, 1]
    const output = transform(100, inputRange, outputRange)

    // Returns 0.5
    return <div>{output}</div>
    }
  • Transforms numbers into other values by mapping them from an input range to an output range.

    Given an input range of [0, 200] and an output range of [0, 1], this function will return a value between 0 and 1. The input range must be a linear series of numbers. The output range can be any supported value type, such as numbers, colors, shadows, arrays, objects and more. Every value in the output range must be of the same type and in the same format.

    import * as React from "react"
    import { Frame, transform } from "framer"

    export function MyComponent() {
    const inputRange = [-200, -100, 100, 200]
    const outputRange = [0, 1, 1, 0]
    const convertRange = transform(inputRange, outputRange)
    const output = convertRange(-150)

    // Returns 0.5
    return <div>{output}</div>
    }

    Type Parameters

    • T

    Parameters

    • inputRange: number[]

      A linear series of numbers (either all increasing or decreasing).

    • outputRange: T[]

      A series of numbers, colors or strings. Must be the same length as inputRange.

    • Optional options: TransformOptions<T>

      Clamp: clamp values to within the given range. Defaults to true.

    Returns ((inputValue) => T)

      • (inputValue): T
      • Parameters

        • inputValue: number

        Returns T

Generated using TypeDoc