Skip to content

Animate

Defined in: utilities/animate/animate.ts:156

Easily animate CSS values. Credit

  • The built-in easings are linear, elastic, quad, quint, circ, back and bounce. You can also pass your own EasingFunction.
  • Animate a relative value with a string: '+25' or '-25' adds to or takes from the value the property has when the animation starts.
  • Animate.to animates CSS values, and can override the settings for that one animation.
  • Animate.delay holds back the animations that come after it. Both return the instance, so calls chain.
  • One Animate is for one element. Only px values, and opacity, can be animated.
  • With CSS transitions most of this is obsolete: use them when you can.

Global configuration

const settings = { duration: 500, easing: 'bounce' } as const;
const animation = new Animate(document.getElementById('el') as HTMLElement, settings);
animation.to({ width: 100 }, {}, () => {
console.log('animation complete');
});

Chaining, with delays

animation
.to({ width: '+25', left: '+10' })
.delay(1000)
.to({ opacity: 0 })
.delay(2000)
.to({ opacity: 1, height: '+50' });

new Animate(element, settings?): Animate

Defined in: utilities/animate/animate.ts:167

HTMLElement

The element to animate.

AnimateOptions

Settings for every animation of this element. Animate.to can override them.

Animate

If element is not an element.

delay(time): this

Defined in: utilities/animate/animate.ts:211

Holds back the animations that are started after this call, until the time is up.

Every delay is counted from the moment you call it, not from the end of the one before. For a second delay of one second after a first of one second, pass 2000.

number

How long to wait, in ms.

this

The instance, so calls can be chained.


to(props, settings?, callback?): this

Defined in: utilities/animate/animate.ts:188

Animates CSS values. Several to() calls can run at the same time, each with its own callback. After a Animate.delay, the call waits for it.

AnimateProps

The properties to animate, and their targets.

AnimateOptions

Overrides the settings of the constructor, for this animation only.

AnimateCallback

Called when this animation has finished.

this

The instance, so calls can be chained.

animation.to({ width: 100, opacity: 0.5 }, { duration: 1000, easing: 'quad' });