new DOMRenderer(rekapi)
rekapi.DOMRenderer
allows you to animate DOM elements. This is
achieved either by CSS @keyframe
animations, or
by per-frame inline style updates — keyframes are defined with the same API
in either case. To render animations with the DOM, just supply any DOM
element to the rekapi.Rekapi
constructor. You may use
document.body
, since it is generally always available:
const rekapi = new Rekapi(document.body);
To use this renderer's API, get a reference to the initialized object:
const domRenderer = rekapi.getRendererInstance(DOMRenderer);
There are separate APIs for playing inline style animations and CSS
@keyframe
animations. For a detailed breakdown of how to choose between
these two APIs and use rekapi.DOMRenderer
effectively, check out the
DOM Rendering in Depth tutorial.
Note: rekapi.DOMRenderer
is added to rekapi.Rekapi#renderers
automatically, there is no reason to call the
constructor yourself in most cases.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
rekapi |
rekapi.Rekapi
|
The |
Extends
Methods
canAnimateWithCSS() → {boolean}
- Source:
Returns:
- Type:
-
boolean
Whether or not the browser supports CSS @keyframe
animations.
getCss(optionsopt) → {string}
Convert the animation to CSS @keyframes
.
- Source:
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
<optional> |
{} |
|
Returns:
- Type:
-
string
isPlaying() → {boolean}
- Source:
Returns:
- Type:
-
boolean
Whether or not a CSS @keyframe
animation is running.
play(iterationsopt, fpsopt)
Play the Rekapi animation as a CSS @keyframe
animation.
Note that this is not the same as rekapi.Rekapi#play
. That method
controls inline style animations, while this method controls CSS
@keyframe
animations.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
iterations |
number
|
<optional> |
How many times the animation should loop.
This can be |
fps |
number
|
<optional> |
How many |
Fires:
prerender(iterationsopt, fpsopt) → {string}
Prerender and cache the CSS animation so that it is immediately ready to
be used when it is needed in the future. The function signature is
identical to rekapi.DOMRenderer#play
. This
is necessary to play a CSS animation and will be automatically called for
you if you don't call it manually, but calling it ahead of time (such as
on page load) will prevent any perceived lag when a CSS @keyframe
animation is started. The prerendered animation is cached for reuse until
the timeline or a keyframe is modified.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
iterations |
number
|
<optional> |
How many times the animation should loop.
This can be |
fps |
number
|
<optional> |
How many |
Returns:
- Type:
-
string
The prerendered CSS string. You likely won't need this, as it is also cached internally.
setActorTransformOrder(actor, orderedTransforms) → {rekapi.Rekapi}
You can decouple transform components in order to animate each property with its own easing curve:
actor
.keyframe(0, {
translateX: '0px',
translateY: '0px',
rotate: '0deg'
})
.keyframe(1500, {
translateX: '200px',
translateY: '200px',
rotate: '90deg'
}, {
translateX: 'easeOutExpo',
translateY: 'easeInSine',
rotate: 'elastic'
});
CSS transform string components are order-dependent, but JavaScript object
properties have an unpredictable order. Rekapi must combine transform
properties supplied to rekapi.Actor#keyframe
(as shown above) into
a single string when it renders each frame. This method lets you change
that order from the default.
However, if you prefer a more standards-oriented approach, Rekapi also
supports combining the transform components yourself, obviating the need
for rekapi.DOMRenderer#setActorTransformOrder
entirely:
actor
.keyframe(0, {
transform: 'translateX(0px) translateY(0px) rotate(0deg)'
})
.keyframe(1500, {
transform: 'translateX(200px) translateY(200px) rotate(90deg)'
}, {
transform: 'easeOutExpo easeInSine elastic'
});
- Source:
Parameters:
Name | Type | Description |
---|---|---|
actor |
rekapi.Actor
|
The |
orderedTransforms |
Array.<string>
|
The array of transform names. The supported array values (and default order) are:
|
Returns:
- Type:
-
rekapi.Rekapi
stop(goToEndopt)
Stop a CSS @keyframe
animation. This also removes any <style>
elements that were dynamically injected into the DOM.
Note that this is not the same as rekapi.Rekapi#stop
. That method
controls inline style animations, while this method controls CSS
@keyframe
animations.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
goToEnd |
boolean
|
<optional> |
If true, skip to the end of the animation. If
false or omitted, set inline styles on the |