createTransform
createTransform produces a new MotionValue derived from one or more source values. Pass a
transformer function, or pass input and output ranges and let motion interpolate between them.
import { createMotionValue, createTransform, motion } from 'motion-solidjs'
const x = createMotionValue(0)
const opacity = createTransform(x, [-100, 0, 100], [0, 1, 0])
const bg = createTransform(x, [-100, 0, 100], ['#36e0c5', '#7c5cff', '#ff4d8d'])
// Function form
const angle = createTransform(() => x.get() * 0.4)
Scroll line 1
Scroll line 2
Scroll line 3
Scroll line 4
Scroll line 5
Scroll line 6
Scroll line 7
Scroll line 8
Scroll line 9
Scroll line 10
Scroll line 11
Scroll line 12
Scroll line 13
Scroll line 14
Scroll line 15
Scroll line 16
Scroll line 17
Scroll line 18
Signatures
createTransform<T>(input: MotionValue, transform: (v: any) => T): MotionValue<T>
createTransform<I, O>(
input: MotionValue<I> | MotionValue<I>[],
inputRange: I[],
outputRange: O[],
options?: { clamp?: boolean; ease?: Easing | Easing[]; mixer?: Mixer<O> },
): MotionValue<O>
createTransform<O>(transform: () => O, deps?: MotionValue[]): MotionValue<O>
Range form interpolates string colors, numbers, complex strings (e.g. '1px solid red'),
and arrays. clamp: false lets the output extrapolate past the bounds.