Full list of CSS & SVG Animatable Properties & Animation Options that are supported
Animatable CSS properties are TypeMissingCSSProperties SVG Presentation Attributes are TypeAnimatableSVGAttributes
CSS properties the ParseTransformableCSSProperties
can parse
Custom Easing has 3 properties they are easing
(all the easings from #easing are supported on top of custom easing functions, like spring, bounce, etc...), numPoints
(the size of the Array the Custom Easing function should create), and decimal
(the number of decimal places of the values within said Array).
Properties | Default Value |
---|---|
easing |
spring(1, 100, 10, 0) |
numPoints |
50 |
decimal |
3 |
By default, Custom Easing support easing functions, in the form,
constant | accelerate | decelerate | accelerate-decelerate | decelerate-accelerate |
---|---|---|---|---|
linear | ease-in / in | ease-out / out | ease-in-out / in-out | ease-out-in / out-in |
ease | in-sine | out-sine | in-out-sine | out-in-sine |
steps | in-quad | out-quad | in-out-quad | out-in-quad |
step-start | in-cubic | out-cubic | in-out-cubic | out-in-cubic |
step-end | in-quart | out-quart | in-out-quart | out-in-quart |
in-quint | out-quint | in-out-quint | out-in-quint | |
in-expo | out-expo | in-out-expo | out-in-expo | |
in-circ | out-circ | in-out-circ | out-in-circ | |
in-back | out-back | in-out-back | out-in-back | |
in-bounce | out-bounce | in-out-bounce | out-in-bounce | |
in-elastic | out-elastic | in-out-elastic | out-in-elastic | |
spring / spring-in | spring-out | spring-in-out | spring-out-in |
All Elastic easing's can be configured using theses parameters,
*-elastic(amplitude, period)
Each parameter comes with these defaults
Parameter | Default Value |
---|---|
amplitude | 1 |
period | 0.5 |
All Spring easing's can be configured using theses parameters,
spring-*(mass, stiffness, damping, velocity)
Each parameter comes with these defaults
Parameter | Default Value |
---|---|
mass | 1 |
stiffness | 100 |
damping | 10 |
velocity | 0 |
You can create your own custom cubic-bezier easing curves. Similar to css you type cubic-bezier(...)
with 4 numbers representing the shape of the bezier curve, for example, cubic-bezier(0.47, 0, 0.745, 0.715)
this is the bezier curve for in-sine
.
Note: the easing
property supports the original values and functions for easing as well, for example, steps(1)
, and etc... are supported.
Note: you can also use camelCase when defining easing functions, e.g. inOutCubic
to represent in-out-cubic
The format to use when defining custom easing functions
CSS Properties that are missing from the type definition
Common CSS Property names with the units "px" as an acceptable value
Cache previously converted CSS values to avoid lots of Layout, Style, and Paint computations when computing CSS values
The default options for every Animate instance
{
keyframes: [],
loop: 1,
delay: 0,
speed: 1,
endDelay: 0,
easing: "ease",
autoplay: true,
duration: 1000,
persist: true,
fillMode: "none",
direction: "normal",
padEndDelay: false,
timeline: document.timeline,
extend: {}
}
From: [https://easings.net]
Read More about easings on MDN
{
"in": "ease-in",
"out": "ease-out",
"in-out": "ease-in-out",
// Sine
"in-sine": "cubic-bezier(0.47, 0, 0.745, 0.715)",
"out-sine": "cubic-bezier(0.39, 0.575, 0.565, 1)",
"in-out-sine": "cubic-bezier(0.445, 0.05, 0.55, 0.95)",
// Quad
"in-quad": "cubic-bezier(0.55, 0.085, 0.68, 0.53)",
"out-quad": "cubic-bezier(0.25, 0.46, 0.45, 0.94)",
"in-out-quad": "cubic-bezier(0.455, 0.03, 0.515, 0.955)",
// Cubic
"in-cubic": "cubic-bezier(0.55, 0.055, 0.675, 0.19)",
"out-cubic": "cubic-bezier(0.215, 0.61, 0.355, 1)",
"in-out-cubic": "cubic-bezier(0.645, 0.045, 0.355, 1)",
// Quart
"in-quart": "cubic-bezier(0.895, 0.03, 0.685, 0.22)",
"out-quart": "cubic-bezier(0.165, 0.84, 0.44, 1)",
"in-out-quart": "cubic-bezier(0.77, 0, 0.175, 1)",
// Quint
"in-quint": "cubic-bezier(0.755, 0.05, 0.855, 0.06)",
"out-quint": "cubic-bezier(0.23, 1, 0.32, 1)",
"in-out-quint": "cubic-bezier(0.86, 0, 0.07, 1)",
// Expo
"in-expo": "cubic-bezier(0.95, 0.05, 0.795, 0.035)",
"out-expo": "cubic-bezier(0.19, 1, 0.22, 1)",
"in-out-expo": "cubic-bezier(1, 0, 0, 1)",
// Circ
"in-circ": "cubic-bezier(0.6, 0.04, 0.98, 0.335)",
"out-circ": "cubic-bezier(0.075, 0.82, 0.165, 1)",
"in-out-circ": "cubic-bezier(0.785, 0.135, 0.15, 0.86)",
// Back
"in-back": "cubic-bezier(0.6, -0.28, 0.735, 0.045)",
"out-back": "cubic-bezier(0.175, 0.885, 0.32, 1.275)",
"in-out-back": "cubic-bezier(0.68, -0.55, 0.265, 1.55)"
}
I don't really want to put in the effort to create a complete list, so instead just look through the animate.css
github and copy and paste the effects you need, into using a CSS Keyframe style JSON object, make sure to read the documentation for KeyframeParse
I suggest @shoelace-style/animations for all your animate.css needs.
or
if you just need some quick effects go to github.com/wellyshen/use-web-animations/ and copy the keyframes
array for the effect you want, remember to say thank you to @wellyshen for all his hardwork, 😂.
Cache the durations at set easing parameters
The default list of easing functions, do note this is different from {@link EASING}
The keys of EASINGS
For better performance push empty elements into EmptyTweenElContainer
The threshold for an infinite loop
Store all the supported transform functions as an Array
Details how to compute each transform function
Cache calculated tween points for commonly used easing functions
Keeps track of how many empty tween elements are in use
Applies the same custom easings to all properties of the object and returns an object with each property having an array of custom eased values
If you use the spring
or spring-in
easings it will also return the optimal duration as a key in the object it returns.
If you set duration
to a number, it will prioritize that duration
over optimal duration given by the spring easings.
Read more about CustomEasing
e.g.
import { animate, ApplyCustomEasing } from "@okikio/animate";
animate({
target: "div",
...ApplyCustomEasing({
border: ["1px solid red", "3 dashed green", "2 solid black"],
translateX: [0, 250],
rotate: ["0turn", 1, 0, 0.5],
"background-color": ["#616aff", "white"],
// You don't need to enter any parameters, you can just use the default values
easing: "spring",
// You can change the size of Array for the CustomEasing function to generate
numPoints: 200,
// The number of decimal places to round, final values in the generated Array
decimal: 5,
// You can also set the duration from here.
// When using spring animations, the duration you set here is not nesscary,
// since by default springs will try to determine the most appropriate duration for the spring animation.
// But the duration value here will override `spring` easings optimal duration value
duration: 3000
})
})
Takes TypeSingleValueCSSProperty
or an array of TypeSingleValueCSSProperty
and adds units approriately
array of numbers, strings and/or an array of array of both e.g. [[25, "50px", "60%"], "25 35 60%", 50]
a unit function to use to add units to TypeSingleValueCSSProperty's
an array of an array of strings with units e.g.
import { CSSArrValue, UnitPX } from "@okikio/animate";
CSSArrValue([
[25, "50px", "60%"],
"25 35 60%",
50
], UnitPX)
//= [
//= [ '25px', '50px', '60%' ],
//= [ '25px', '35px', '60%' ],
//= [ '50px' ]
//= ]
Removes dashes from CSS properties & maps the values to camelCase keys
Returns a closure function, which adds units to numbers, strings or arrays of both
a unit function to use to add units to TypeSingleValueCSSProperty's
if input is a string split it into an array at the comma's, and add units else if the input is a number add the default units otherwise if the input is an array of both add units according to addCSSUnit
Convert string easing to their proper form
Converts "10px solid red #555 rgba(255, 0,5,6, 7) " to [ '10px', 'solid', 'red', '#555', 'rgba(255, 0,5,6, 7)' ]
Generates an Array of values using easing functions which in turn create the effect of custom easing. To use this properly make sure to set the easing animation option to "linear". Check out a demo of CustomEasing at https://codepen.io/okikio/pen/abJMWNy?editors=0010
Custom Easing has 3 properties they are easing
(all the easings from EasingFunctions are supported on top of custom easing functions like spring, bounce, etc...), numPoints
(the size of the Array the Custom Easing function should create), and decimal
(the number of decimal places of the values within said Array).
Properties | Default Value |
---|---|
easing |
spring(1, 100, 10, 0) |
numPoints |
50 |
decimal |
3 |
By default, Custom Easing support easing functions, in the form,
constant | accelerate | decelerate | accelerate-decelerate | decelerate-accelerate |
---|---|---|---|---|
linear | ease-in / in | ease-out / out | ease-in-out / in-out | ease-out-in / out-in |
ease | in-sine | out-sine | in-out-sine | out-in-sine |
steps | in-quad | out-quad | in-out-quad | out-in-quad |
step-start | in-cubic | out-cubic | in-out-cubic | out-in-cubic |
step-end | in-quart | out-quart | in-out-quart | out-in-quart |
in-quint | out-quint | in-out-quint | out-in-quint | |
in-expo | out-expo | in-out-expo | out-in-expo | |
in-circ | out-circ | in-out-circ | out-in-circ | |
in-back | out-back | in-out-back | out-in-back | |
in-bounce | out-bounce | in-out-bounce | out-in-bounce | |
in-elastic | out-elastic | in-out-elastic | out-in-elastic | |
spring / spring-in | spring-out | spring-in-out | spring-out-in |
All Elastic easing's can be configured using theses parameters,
*-elastic(amplitude, period)
Each parameter comes with these defaults
Parameter | Default Value |
---|---|
amplitude | 1 |
period | 0.5 |
All Spring easing's can be configured using theses parameters,
spring-*(mass, stiffness, damping, velocity)
Each parameter comes with these defaults
Parameter | Default Value |
---|---|
mass | 1 |
stiffness | 100 |
damping | 10 |
velocity | 0 |
You can create your own custom cubic-bezier easing curves. Similar to css you type cubic-bezier(...)
with 4 numbers representing the shape of the bezier curve, for example, cubic-bezier(0.47, 0, 0.745, 0.715)
this is the bezier curve for in-sine
.
Note: the easing
property supports the original values and functions for easing as well, for example, steps(1)
, and etc... are supported.
Note: you can also use camelCase when defining easing functions, e.g. inOutCubic
to represent in-out-cubic
Suggestion: if you decide to use CustomEasing on one CSS property, I suggest using CustomEasing or ApplyCustomEasing on the rest (this is no longer necessary, but for the sake of readability it's better to do)
e.g.
import { animate, CustomEasing, EaseOut, Quad } from "@okikio/animate";
animate({
target: "div",
// Notice how only, the first value in the Array uses the "px" unit
border: CustomEasing(["1px solid red", "3 dashed green", "2 solid black"], {
// This is a custom easing function
easing: EaseOut(Quad)
}),
translateX: CustomEasing([0, 250], {
easing: "linear",
// You can change the size of Array for the CustomEasing function to generate
numPoints: 200,
// The number of decimal places to round, final values in the generated Array
decimal: 5,
}),
// You can set the easing without an object
// Also, if units are detected in the values Array,
// the unit of the first value in the values Array are
// applied to other values in the values Array, even if they
// have prior units
rotate: CustomEasing(["0turn", 1, 0, 0.5], "out"),
"background-color": CustomEasing(["#616aff", "white"]),
easing: "linear"
}),
// TIP... Use linear easing for the proper effect
easing: "linear"
})
returns a CustomEasingOptions object from a easing "string", or function
Converts easing functions to their in-out
counter parts
Converts easing functions to their out
counter parts
Converts easing functions to their out-in
counter parts
Create an Array of tween points using easing functions.
The array is numPoints
large, which is by default 50.
Easing function can be custom defined, so, instead of string you can use functions,
e.g.
tweenPts({
easing: t => t,
numPoints: 50
})
Converts users input into a usable easing function string
easing functions; EasingKeys, cubic-bezier, steps, linear, etc...
an easing function that KeyframeEffect
can accept
Re-maps a number from one range to another. Numbers outside the range are not clamped to 0 and 1, because out-of-range values are often intentional and useful.
Allows you to quickly convert CSS like JSON into keyframes
CSS style JSON; check the example to understand what I mean
Similar to ParseTransformableCSSProperties except it transforms the CSS properties in each Keyframe
an array of keyframes with transformable CSS properties
an array of keyframes, with transformed CSS properties
Removes the need for the full transform statement in order to use translate, rotate, scale, skew, or perspective including their X, Y, Z, and 3d varients Also, adds the ability to use single string or number values for transform functions
Note: the transform
animation option will override all transform function properties
Note: the order of where/when you define transform function matters, for example, depending on the order you define translate
, and rotate
, you can create change the radius of the rotation
the CSS properties to transform
an object with a properly formatted transform
and opactity
, as well as other unformatted CSS properties
Easing Functions from anime.js, they are tried and true, so, its better to use them instead of other alternatives
Returns an array containing [easing pts, duration]
, it's meant to be a self enclosed way to create spring easing.
Springs have an optimal duration; using getEasingDuration()
we are able to have the determine the optimal duration for a spring with given parameters.
By default it will only give the optimal duration for spring
or spring-in
easing, this is to avoid infinite loops caused by the getEasingDuration()
function.
Internally the SpringEasing
uses CustomEasing, read more on it, to understand how the SpringEasing
function works.
e.g.
import { animate, SpringEasing } from "@okikio/animate";
// `duration` is the optimal duration for the spring with the set parameters
let [translateX, duration] = SpringEasing([0, 250], "spring(5, 100, 10, 1)");
// or
// `duration` is 5000 here
let [translateX, duration] = SpringEasing([0, 250], {
easing: "spring(5, 100, 10, 1)",
numPoints: 50,
duration: 5000,
decimal: 3
});
animate({
target: "div",
translateX,
duration
});
Returns an AnimationOption callback, with support for stagger and CustomEasing. Thus all the same options and restrictions apply, make sure you read more on stagger and CustomEasing.
StaggerCustomEasing
only supports array range values.
To use StaggerCustomEasing
you need to do this,
import { animate, stagger, StaggerCustomEasing } from "@okikio/animate";
animate({
target: ".div",
translate: StaggerCustomEasing([0, 250], {
// To set stagger options you need to do this
stagger: { from "center" },
// These options are for `CustomEasing`
easing: "out-elastic",
numPoints: 150
}),
delay: stagger(100),
fillMode: "both",
easing: "linear",
duration: 5000
})
Check out demos on Codepen
These Easing Functions are based off of the Sozi Project's easing functions https://github.com/sozi-projects/Sozi/blob/d72e44ebd580dc7579d1e177406ad41e632f961d/src/js/player/Timing.js
Function adds "deg" unit to numbers
Parses CSSValues and adds the "deg" unit if required
Function doesn't add any units by default
Parses CSSValues without adding any units
Function adds "px" unit to numbers
Parses CSSValues and adds the "px" unit if required
Returns a closure Function, which adds a unit to numbers but simply returns strings with no edits assuming the value has a unit if it's a string
the default unit to give the CSS Value
if value already has a unit (we assume the value has a unit if it's a string), we return it; else return the value plus the default unit
It fills in the gap between different size transform functions, so, for example,
{
translateX: [50, 60, 80, 90],
scale: [0.5, 2]
}
There are more values of translateX
, so the transform
property created will look like this,
{
transform: [
"translateX(50px) scale(0.5)",
"translateX(60px) scale(2)",
"translateX(80px)",
"translateX(90px)"
]
}
arrFill
interpolates between all missing portions of transform functions, and helps create a uniform size transform property,
e.g.
{
transform: [
"translateX(50px) scale(0.5)",
"translateX(60px) scale(1)",
"translateX(80px) scale(1.5)",
"translateX(90px) scale(2)"
]
}
Convert a dash-separated string into camelCase strings (opposite of convertToDash)
Convert a camelCase string to a dash-separated string (opposite of camelCase)
Creates a new empty tween element
Creates the transform property text
The default ease-in
easing function
Merges 2-dimensional Arrays into a single 1-dimensional array
The spring easing function will only look smooth at certain durations, with certain parameters. This functions returns the optimal duration to create a smooth springy animation based on physics
Note: it can also be used to determine the optimal duration of other types of easing function, but be careful of "in-"
easing functions, because of the nature of the function it can sometimes create an infinite loop, I suggest only using
getEasingDuration
for spring
, specifically "out-spring" and "spring"
Returns the unit of a string, it does this by removing the number in the string
Use the color-rgba
npm package, to convert all color formats to an Array of rgba values,
e.g. [red, green, blue, alpha]
. Then, use the interpolateNumber functions to interpolate over the array
Note: the red, green, and blue colors are rounded to intergers with no decimal places, while the alpha color gets rounded to a specific decimal place
Make sure to read interpolateNumber.
Interpolates all types of values including number, string, color, and complex values. Complex values are values like "10px solid red", that border, and other CSS Properties use.
Make sure to read interpolateNumber, interpolateString, interpolateColor, and interpolateUsingIndex.
Given an Array of numbers, estimate the resulting number, at a t
value between 0 to 1
Based on d3.interpolateBasis [https://github.com/d3/d3-interpolate#interpolateBasis],
check out the link above for more detail.
Basic interpolation works by scaling t
from 0 - 1, to some start number and end number, in this case lets use
0 as our start number and 100 as our end number, so, basic interpolation would interpolate between 0 to 100.
If we use a t
of 0.5, the interpolated value between 0 to 100, is 50.
interpolateNumber takes it further, by allowing you to interpolate with more than 2 values,
it allows for multiple values.
E.g. Given an Array of values [0, 100, 0], and a t
of 0.5, the interpolated value would become 100.
Functions the same way interpolateNumber works.
Convert strings to numbers, and then interpolates the numbers,
at the end if there are units on the first value in the values
array,
it will use that unit for the interpolated result.
Make sure to read interpolateNumber.
Given an Array of values, find a value using t
(t
goes from 0 to 1), by
using t
to estimate the index of said value in the array of values
Determines if an object is empty
If a value can be converted to a valid number, then it's most likely a number
Determines whether value is an pure object (not array, not function, etc...)
Checks if a value is valid/truthy; it counts empty arrays and strings as falsey, as well as null, undefined, and NaN, everything else is valid
Note: 0 counts as valid
anything
true or false
Acts like array.map(...) but for functions
Return a copy of the object without the keys specified in the keys argument
arrays of keys to remove from the object
the object in question
a copy of the object without certain keys
Convert easing parameters to Array of numbers, e.g. "spring(2, 500)" to [2, 500]
Convert the words "from", and "to" as well as percentage or numbers to offset value between 0 and 1
Parses the different ways to define options, and returns a merged options object
Return a copy of the object with only the keys specified in the keys argument
arrays of keys to keep from the object
the object in question
a copy of the object with only certain keys
Creates a new Queue instance, and passes the options to the constructor
Generates random values within a range of values
Allows you to register new easing functions
Allows you to register multiple new easing functions
If the input value is a string starting with with "=" (the equal sign), it removes the "=" and return the remaining number Otherwise, parse string or numbers to a number and add the base number to it, to create relative numbers (relative to the base value)
map t
from 0 to 1, to start
to end
Creates complex staggered animations, it does it by creating a closure function and using it as an AnimationOption Based on animejs's stagger function, it function the same way
Staggering allows you to animate multiple elements with follow through and overlapping action.
It can be used like this,
import { animate, stagger } from "@okikio/animate";
animate({
target: ".div",
// `stagger` accepts range values but only an Array of 2 values are accepted,
// the values can be either a "string" or a "number".
// `stagger` distributes values evenly between two numbers,
// so, given 5 elements, translate on the first element will be 0,
// on the second element 50, on the third element 100, etc...
// the equation is:
// (start value or first value in array range) + (((second value in the range) - (first value in the range)) / (total number of elements)) * (current index of element)
// For an array of range `[-360, 360]`, 5 elements, and an undefined start value, you will get:
//= -360 + ((360 - (-360)) / 5) * 0
//= -360 + ((360 - (-360)) / 5) * 1
//= -360 + ((360 - (-360)) / 5) * 2
//= -360 + ((360 - (-360)) / 5) * 3
//= -360 + ((360 - (-360)) / 5) * 4
translate: stagger([0, 250]),
// Single value staggers are also possible.
// This increase delay by 100ms for each element.
delay: stagger(100),
fillMode: "both",
easing: "linear",
duration: 5000
});
stagger can also be used for grids. For grids you do this,
import { animate, stagger } from "@okikio/animate";
animate({
target: ".div",
// For grids you need to specify the size of the grid via stagger options
// { grid: [number of columns, number of rows] }
// and in this scenario we also need to specify the axis
// { axis: "x" or "y" }
translate: stagger([0, 30], {
grid: [14, 5],
axis: "x"
}),
// Single value staggers are still possible.
delay: stagger(100, { grid: [14, 5] }),
fillMode: "both",
easing: "linear",
duration: 5000
});
the full list of staggering options are:
Stagger option | Types | Default value | Use case |
---|---|---|---|
start | Number | String | The first value in an Array range or 0 | Starts the staggering effect from a specific value. |
axis | "x" | "y" | Undefined | Forces the direction of a grid staggering effect. It's often used together with the grid stagger option |
from | Number | "center" | "first" | "last" | 0 | Starts the stagger effect from a specific element. |
direction | "reverse" | "normal" | Undefined | Changes the order in which the stagger effect operates. e.g. instead of top to bottom, go bottom to top. |
easing | String | Function | Undefined | Stagger values using an easing function. Allows stagger effect to have certain easing characteristics, e.g. in-out-quad, is very smooth so, the stagger effect will also be very smooth |
grid | Array of 2 values, [number of columns, number of rows] | Undefined | Stagger values based on a 2D array that states the [number of columns, number of rows]. |
Check out demos on Codepen as well as animejs's stagger documentation
Because stagger returns an AnimationOption callback, it fundementally doesn't work with CustomEasing, so, you need to use StaggerCustomEasing to enable custom easing.
Convert the input to an array For strings if type == "split", split the string at spaces, if type == "wrap" wrap the string in an array For array do nothing For everything else wrap the input in an array
Convert transform function properties to CSS variables to create the desired animation e.g.
```js toCSSVars({ translate: ["0px 60px", "100px 100px"], translateX: ["60px", "500px"], translateY: ["60px", "500px"], });
// { // "--translate0": [ // "0px", // "100px" // ], // "--translate1": [ // "60px", // "100px" // ], // "--translateX": [ // "60px", // "500px" // ], // "--translateY": [ // "60px", // "500px" // ] // }
Rounds numbers to a fixed decimal place
Convert colors to an [r, g, b, a] Array
Converts values to strings
Flips the rows and columns of 2-dimensional arrays
Read more on underscorejs.org & lodash.com
returns the new array of grouped elements
Convert value to string, then trim any extra white space and line terminator characters from the string.
Creates new instances of AnimateAttributes
Generated using TypeDoc
Animatable CSS Properties