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
Common CSS Property names with the units "px" as an acceptable value
The default options for every Animate instance
{
keyframes: [],
loop: 1,
delay: 0,
speed: 1,
endDelay: 0,
easing: "ease",
autoplay: true,
duration: 1000,
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
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 all the empty tween elements
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.
[
[ '25px', '35px', ' 60%' ],
[ '50px', '60px', '70px' ]
]
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
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 outcounter 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
})
Based on https://github.com/w3c/csswg-drafts/issues/229#issuecomment-861415901
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
Removes dashes from CSS properties & maps the values to the camelCase keys
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
});
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
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"
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
If a value can be converted to a valid number, then it's most likely a number
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
Allows you to register new easing functions
Allows you to register multiple new easing functions
map t from 0 to 1, to start to end
Convert the input to an array For strings split them at commas For array do nothing For everything else wrap the input in an array
Rounds numbers to a fixed decimal place
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.
Uses the change in opacity (from the tween function) to interpolate the value of other elements
e.g.
import { tweenAttr } from "@okikio/animate";
import { interpolate } from "polymorph-js";
let startPath = usingPolymorphPathEl.getAttribute("d");
let endPath = "M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z";
// This is an svg path interpolate function
// If used in tandem with `tweenAttr`, you can create morphing animations
let morph = interpolate([startPath, endPath], {
addPoints: 0,
origin: { x: 0, y: 0 },
optimize: "fill",
precision: 3
});
// `tweenAttr` supports all Animation Options.
// The first argument in Animation Options callbacks are set to the progress of the animation beteen 0 and 1, while the other arguments are moved 1 right
// So, animation options can look like this
// `(progress: number, i: number, len: number, el: HTMLElement) => {
// return progress;
// }`
tweenAttr({
target: "svg path",
d: progress => morph(progress)
});
// `tweenAttr` can automatically choose between custom easing functions and or normal easings
tweenAttr({
target: ".div",
targets: ".el",
width: 250,
height: ["500px", 600],
easing: "spring"
// If you want to update styles instead of attributes,
// you can change this to "style"
}, "style");
Read more about tween
Generated using TypeDoc
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), anddecimal(the number of decimal places of the values within said Array).easingspring(1, 100, 10, 0)numPoints50decimal3