Motion Value API

Detailed listing of all motion value related features of Svelte Motion. A lot of the wording is directly copied from framer-motion, Copyright (c) 2018 Framer B.V. MIT License.

InputRange

number[]
An input range must be a linear series of numbers.

MotionPoint

{x: MotionValue <number>, y: MotionValue <number>}

MotionValue

class<T>
`MotionValue` is used to track the state and velocity of motion values.

see example

MultiTransformer

<Input,Output>(i:Input[]) => Output
An array of MotionValue s that will pass their latest values through `transform` to update the returned MotionValue .

ScrollMotionValues

interface
Collection of scroll related motion values returned by useElementScroll or useViewportScroll .

SingleTransformer

<Input,Output>(i:Input) => Output
A function that accepts the latest value from `input` and returns a new value.

Subscriber

(value: T) => void
Function to react on changes in motion value

Unsubscriber

() => void
Function to call when motion value or store should not react on subscription anymore. From 'svelte/store'.

useElementScroll

(ref?: {current?:Node}) => ScrollMotionValues
Returns MotionValues that update when the provided element scrolls:

- `scrollX` - Horizontal scroll distance in pixels.
- `scrollY` - Vertical scroll distance in pixels.
- `scrollXProgress` - Horizontal scroll progress between `0` and `1`.
- `scrollYProgress` - Vertical scroll progress between `0` and `1`.

This element must be set to `overflow: scroll` on either or both axes to report scroll offset.

useMotionTemplate

(fragments: TemplateStringsArray, ...values: MotionValue []) => MotionValue <string> & { reset }
Combine multiple motion values into a new one using a string template literal.

see example

useMotionValue

(initialValue : T) => MotionValue <T>
Creates a MotionValue to track the state and velocity of a value.

Usually, these are created automatically. For advanced use-cases, like use with useTransform , you
can create MotionValue s externally
and pass them into the animated component via the `style` prop.

see example

useSpring

(source: MotionValue | number, config?: SpringOptions ) => MotionValue <T> & { reset }
Creates a `MotionValue` that, when `set`, will use a spring animation to animate to its new state.It can either work as a stand-alone `MotionValue` by initialising it with a value, or as a subscriberto another `MotionValue`.

useTransform

(value: MotionValue <number>, inputRange: InputRange , outputRange: O[], options?: TransformOptions <O>) => MotionValue <O> & { reset }
Create a MotionValue that transforms the output of another MotionValue by mapping it from one range of values into another.
The input range must be a linear series of numbers. The output range
can be any value type supported by Svelte Motion: numbers, colors, shadows, etc.

Every value in the output range must be of the same type and in the same format.

or

(input: MotionValue <I>, transformer: SingleTransformer <I, O>) => MotionValue <O> & { reset}
Create a MotionValue that transforms the output of another MotionValue through a function.

or

(input: MotionValue <string | number>[], transformer: MultiTransformer <I, O>) => MotionValue <O> & { reset }
Pass an array of MotionValue s and a function to combine them.

see example

useVelocity

(value: MotionValue <number>) => MotionValue <number>
Creates a MotionValue that updates when the velocity of the provided MotionValue changes.

see example

useViewportScroll

(ref?: {current?:Node}) => ScrollMotionValues
Returns MotionValues that update when the viewport scrolls.

**Warning:** Setting `body` or `html` to `height: 100%` or similar will break the `Progress`
values as this breaks the browser's capability to accurately measure the page length.