Animate
Defined in: utilities/animate/animate.ts:156
Easily animate CSS values. Credit
- The built-in easings are
linear,elastic,quad,quint,circ,backandbounce. 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
Animateis for one element. Only px values, andopacity, can be animated. - With CSS transitions most of this is obsolete: use them when you can.
Examples
Section titled “Examples”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' });Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Animate(
element,settings?):Animate
Defined in: utilities/animate/animate.ts:167
Parameters
Section titled “Parameters”element
Section titled “element”HTMLElement
The element to animate.
settings?
Section titled “settings?”Settings for every animation of this element. Animate.to can override them.
Returns
Section titled “Returns”Animate
Throws
Section titled “Throws”If element is not an element.
Methods
Section titled “Methods”delay()
Section titled “delay()”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.
Parameters
Section titled “Parameters”number
How long to wait, in ms.
Returns
Section titled “Returns”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.
Parameters
Section titled “Parameters”The properties to animate, and their targets.
settings?
Section titled “settings?”Overrides the settings of the constructor, for this animation only.
callback?
Section titled “callback?”Called when this animation has finished.
Returns
Section titled “Returns”this
The instance, so calls can be chained.
Example
Section titled “Example”animation.to({ width: 100, opacity: 0.5 }, { duration: 1000, easing: 'quad' });