Skip to content

steps

Builds the easing function of CSS steps(count, position): progress moves by jumps instead of continuously, for frame-by-frame sprites, ticking counters, or a design tool’s “instant” transition.

The input is clamped to [0, 1], like cubicBezier.

Available since v3.1.5

import { steps } from '@helpers4/animation';
// or, from the all-in-one package (same code, one install):
import { steps } from 'helpers4/animation';
steps(count: number, position: StepPosition): function
ParameterTypeDescription
countnumberNumber of steps, a positive integer (at least 2 with `‘jump-none’`)
positionStepPositionWhere the jumps happen — see StepPosition. Defaults to `‘jump-end’`.

function — The easing function

Progress moves by jumps instead of continuously.

const fourFrames = steps(4);
fourFrames(0.3) // => 0.25
fourFrames(1)   // => 1

With ‘jump-start’, the first jump happens right away.

steps(4, 'jump-start')(0.3) // => 0.5

Where the jumps of a steps easing happen, as in CSS steps():

  • 'jump-end' (or 'end', the default): the last jump at the end, so the first value lasts the first step;
  • 'jump-start' (or 'start'): the first jump at the start;
  • 'jump-both': a jump at both ends, so neither 0 nor 1 is held;
  • 'jump-none': no jump at either end, 0 and 1 are held for a step each.
type StepPosition = 'jump-start' | 'jump-end' | 'jump-none' | 'jump-both' | 'start' | 'end'

View source on GitHub