applyOffset creates a function that measures the offset of any given value from the initial from, and applies it to to.


import { applyOffset } from '@popmotion/popcorn';


applyOffset can be used both when you know the initial value you want to measure the offset from, and when you don’t.

With an initial value

applyOffset(100, 0)(101) // 1

Without an initial value

If we don’t provide an initial from value, the first value we call the returned function will be considered from and apply to with a delta of 0.

const applyPointerMovementToX = applyOffset(x);

applyPointerMovement(100); // x
applyPointerMovement(120); // x + 20


applyOffset(from: number, to: number): (v: number) => number;
applyOffset(to: number): (v: number) => number;