Documentation

Documentation

JavaScript

transformValue

transformValue

transformValue creates a new read-only motion value computed from the output of one or more motion values.

const blur = motionValue(0)
const filter = transformValue(() => `blur(${blur.get()}px)`)

styleEffect("img", { filter })

This is useful for combining multiple motion values into a single value, or performing calculations on a motion value's output.

const scale = motionValue(1)
const inverseScale = transformValue(() => 1 / scale.get())

styleEffect(".parent", { scale })
styleEffect(".child", { scale: inverseScale })

Usage

transformValue accepts a single function, that returns the computed output of one or more other motion values.

import { motionValue, transformValue } from "motion"

const x = motionValue(0)
const doubleX = transformValue(() => x.get() * 2)

Any motion values that call .get() in this function will be tracked, so when they update, the motion value returned from transformValue will also update.

doubleX.on("change", (latest) => console.log(latest))

x.set(10) // doubleX will log 20

Compose

Motion values returned from transformValue can be composed into other transformValue callbacks:

const x = motionValue(0)
const y = motionValue(0)
const rotate = transformValue(() => x.get() + y.get())
const transform = transformValue(() => `translate3d(${x.get()}px ${y.get()}px 0) rotate(${rotate.get()}deg)`)

transformValue creates a new read-only motion value computed from the output of one or more motion values.

const blur = motionValue(0)
const filter = transformValue(() => `blur(${blur.get()}px)`)

styleEffect("img", { filter })

This is useful for combining multiple motion values into a single value, or performing calculations on a motion value's output.

const scale = motionValue(1)
const inverseScale = transformValue(() => 1 / scale.get())

styleEffect(".parent", { scale })
styleEffect(".child", { scale: inverseScale })

Usage

transformValue accepts a single function, that returns the computed output of one or more other motion values.

import { motionValue, transformValue } from "motion"

const x = motionValue(0)
const doubleX = transformValue(() => x.get() * 2)

Any motion values that call .get() in this function will be tracked, so when they update, the motion value returned from transformValue will also update.

doubleX.on("change", (latest) => console.log(latest))

x.set(10) // doubleX will log 20

Compose

Motion values returned from transformValue can be composed into other transformValue callbacks:

const x = motionValue(0)
const y = motionValue(0)
const rotate = transformValue(() => x.get() + y.get())
const transform = transformValue(() => `translate3d(${x.get()}px ${y.get()}px 0) rotate(${rotate.get()}deg)`)

transformValue creates a new read-only motion value computed from the output of one or more motion values.

const blur = motionValue(0)
const filter = transformValue(() => `blur(${blur.get()}px)`)

styleEffect("img", { filter })

This is useful for combining multiple motion values into a single value, or performing calculations on a motion value's output.

const scale = motionValue(1)
const inverseScale = transformValue(() => 1 / scale.get())

styleEffect(".parent", { scale })
styleEffect(".child", { scale: inverseScale })

Usage

transformValue accepts a single function, that returns the computed output of one or more other motion values.

import { motionValue, transformValue } from "motion"

const x = motionValue(0)
const doubleX = transformValue(() => x.get() * 2)

Any motion values that call .get() in this function will be tracked, so when they update, the motion value returned from transformValue will also update.

doubleX.on("change", (latest) => console.log(latest))

x.set(10) // doubleX will log 20

Compose

Motion values returned from transformValue can be composed into other transformValue callbacks:

const x = motionValue(0)
const y = motionValue(0)
const rotate = transformValue(() => x.get() + y.get())
const transform = transformValue(() => `translate3d(${x.get()}px ${y.get()}px 0) rotate(${rotate.get()}deg)`)

transformValue

Examples

Go beyond the basics

Motion+ is a one-time fee, lifetime membership.

As well as premium Motion features, early access content, and a private Discord community, you'll unlock access to the source code of 90+ premium examples that take the APIs on this page to the next level.

Loading...
Loading...
Loading...
Stay in the loop

Subscribe for the latest news & updates.

Stay in the loop

Subscribe for the latest news & updates.