Animate dom elements using the web animation api. https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API This set of animations is just a few opinionated animations which currently include things like fading or translateY. You can either run them on a group, or individually. Configuration can be passed directly, or applied to data attributes on the target element. Data attributes to be placed on the element if not using the options object are: data-animation-delay
, data-animation-duration
, data-animation-easing
, data-animation-types
, data-translate-distance-from
, data-translate-distance-to
.
- Since
- 1.5.0
- Source
Methods
(inner) end(target, options)
End the animation.
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
target | HTMLElement | The target element to animate. | ||||||||||||
options | object | The options for the animation that are needed to determine what type of properties are applied to the element at the end of the animation. Properties
|
- Since
- 1.5.0
- Source
(inner) getAnimationKeyframes(target, options) → {Array}
Get the keyframes for the animation. Follows this format https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats
Name | Type | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
target | HTMLElement | The target element to animate. | ||||||||||||||||||
options | object | The options for the animation that are needed to form the Keyframe object. Properties
|
- Since
- 1.5.0
- Source
The Keyframe objects.
- Type:
- Array
(inner) run(target, options) → {void}
Animate a single element.
Name | Type | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
target | HTMLElement | The target element to animate. | |||||||||||||||||||||||||||
options | object | The options for the animation that are needed to determine what type of properties are applied to the element at the end of the animation. Properties
|
- Since
- 1.5.0
- Source
- Type:
- void
import { animate } from '@gravityforms/utils';
const animateExample = () => {
const logo = getNode( '.gform-splash__header .gform-logo', document, true );
animate.run( logo, {
types: 'fadeIn translateY',
distanceFrom: '-50px',
distanceTo: '0px',
duration: 1000,
easing: 'ease-in-out',
delay: 500,
onInit: () => {
console.log( 'Animation initializing!' );
},
onAnimateStart: () => {
console.log( 'Animation starting!' );
},
onAnimateEnd: () => {
console.log( 'Animation complete!' );
},
} );
};
(inner) runGroup(entries) → {void}
Animate a group of elements.
Name | Type | Description |
---|---|---|
entries | Array | The elements to animate. An array containing a target entry and an options entry that follows the structure of the run function options object. |
- Since
- 1.5.0
- Source
- Type:
- void
import { animate } from '@gravityforms/utils';
const animateExample = () => {
const logo = getNode( '.gform-splash__header .gform-logo', document, true );
const heading = getNode( '.gform-splash__header h1', document, true );
const text = getNode( '.gform-splash__header p', document, true );
const button = getNode( '.gform-splash__header .gform-button', document, true );
const reviews = getNode( '.gform-splash__header .gform-reviews', document, true );
const defaults = {
onAnimateEnd: () => {
console.log( `hello from: ${ performance.now() }` );
},
distance: -20,
duration: 600,
easing: 'cubic-bezier(0.455, 0.030, 0.515, 0.955)',
types: 'fadeIn translateY',
};
animate.runGroup( [
{ target: logo, options: { ...defaults } },
{ target: heading, options: { callback: defaults.callback } }, // this one uses data attributes or internal defaults instead since no options where passed here.
{ target: text, options: { ...defaults, delay: 200 } },
{ target: button, options: { ...defaults, delay: 300 } },
{ target: reviews, options: { ...defaults, delay: 400 } },
] );
};