Classes
Methods
(static) interpolate(from, to, position, easing, delayopt) → {Object}
Compute the midpoint of two Objects. This method effectively calculates a
specific frame of animation that shifty.Tweenable#tween
does many times
over the course of a full tween.
import { interpolate } from 'shifty';
const interpolatedValues = interpolate({
width: '100px',
opacity: 0,
color: '#fff'
}, {
width: '200px',
opacity: 1,
color: '#000'
},
0.5
);
console.log(interpolatedValues); // Logs: {opacity: 0.5, width: "150px", color: "rgb(127,127,127)"}
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
from |
Object
|
The starting values to tween from. |
||
to |
Object
|
The ending values to tween to. |
||
position |
number
|
The normalized position value (between |
||
easing |
Object.<(string|shifty.easingFunction)>
|
string
|
shifty.easingFunction
|
The easing curve(s) to calculate the midpoint against. You can
reference any easing function attached to |
||
delay |
number
|
<optional> |
0 |
Optional delay to pad the beginning of the
interpolated tween with. This increases the range of |
Returns:
- Type:
-
Object
(static) processTweens()
Process all tweens currently managed by Shifty for the current tick. This
does not perform any timing or update scheduling; it is the logic that is
run by the scheduling functionality. Specifically, it computes the state
and calls all of the relevant shifty.tweenConfig
functions supplied
to each of the tweens for the current point in time (as determined by shifty.Tweenable.now
.
This is a low-level API that won't be needed in the majority of situations.
It is primarily useful as a hook for higher-level animation systems that are
built on top of Shifty. If you need this function, it is likely you need to
pass something like () => {}
to shifty.Tweenable.setScheduleFunction
, override shifty.Tweenable.now
and manage the scheduling logic yourself.
(static) setBezierFunction(name, x1, y1, x2, y2) → {shifty.easingFunction}
Create a Bezier easing function and attach it to shifty.Tweenable.formulas
. This function gives you total control over the
easing curve. Matthew Lein's Ceaser is a
useful tool for visualizing the curves you can make with this function.
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
The name of the easing curve. Overwrites the old
easing function on |
x1 |
number
|
|
y1 |
number
|
|
x2 |
number
|
|
y2 |
number
|
Returns:
- Type:
-
shifty.easingFunction
The shifty.easingFunction
that was
attached to shifty.Tweenable.formulas
.
(static) tween(configopt) → {external:Promise}
Standalone convenience method that functions identically to
shifty.Tweenable#tween
. You can use this to create tweens without
needing to set up a shifty.Tweenable
instance.
import { tween } from 'shifty';
tween({ from: { x: 0 }, to: { x: 10 } }).then(
() => console.log('All done!')
);
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
config |
shifty.tweenConfig
|
<optional> |
{} |
Returns:
- Type:
-
external:Promise
This Promise
has a property called tweenable
that is the shifty.Tweenable
instance that is running the tween.
(static) unsetBezierFunction(name) → {boolean}
delete
an easing function from shifty.Tweenable.formulas
. Be
careful with this method, as it delete
s whatever easing formula matches
name
(which means you can delete standard Shifty easing functions).
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
The name of the easing function to delete. |
Returns:
- Type:
-
boolean
Whether or not the functions was delete
d.
Type Definitions
afterTweenFilter(tweenable)
Is called right after a tween is processed in a tick.
Parameters:
Name | Type | Description |
---|---|---|
tweenable |
shifty.Tweenable
|
The |
beforeTweenFilter(tweenable)
Is called right before a tween is processed in a tick.
Parameters:
Name | Type | Description |
---|---|---|
tweenable |
shifty.Tweenable
|
The |
doesApplyFilter(tweenable) → {boolean}
Is called when a tween is created to determine if a filter is needed. Filters are only added to a tween when it is created so that they are not unnecessarily processed if they don't apply during an update tick.
Parameters:
Name | Type | Description |
---|---|---|
tweenable |
shifty.Tweenable
|
The |
Returns:
- Type:
-
boolean
easingFunction(position) → {number}
Parameters:
Name | Type | Description |
---|---|---|
position |
number
|
The normalized (0-1) position of the tween. |
Returns:
- Type:
-
number
The curve-adjusted value.
filter
An Object that contains functions that are called at key points in a tween's
lifecycle. Shifty can only process Number
s internally, but filters can
expand support for any type of data. This is the mechanism that powers
string interpolation.
Properties:
Name | Type | Description |
---|---|---|
doesApply |
shifty.doesApplyFilter
|
Is called when a tween is created. |
tweenCreated |
shifty.tweenCreatedFilter
|
Is called when a tween is created. |
beforeTween |
shifty.beforeTweenFilter
|
Is called right before a tween starts. |
afterTween |
shifty.afterTweenFilter
|
Is called right after a tween ends. |
Type:
-
Object
promisedData
Properties:
Name | Type | Description |
---|---|---|
state |
Object
|
The current state of the tween. |
data |
Object
|
The |
tweenable |
shifty.Tweenable
|
The |
Type:
-
Object
renderFunction(state, dataopt, timeElapsed)
Gets called for every tick of the tween. This function is not called on the final tick of the animation.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
state |
Object
|
The current state of the tween. |
|
data |
Object
|
undefined
|
<optional> |
User-defined data provided via a |
timeElapsed |
number
|
The time elapsed since the start of the tween. |
scheduleFunction(callback, timeout)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function
|
|
timeout |
number
|
startFunction(state, dataopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
state |
Object
|
The current state of the tween. |
|
data |
Object
|
undefined
|
<optional> |
User-defined data provided via a |
tweenConfig
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
from |
Object
|
<optional> |
Starting position. If omitted, |
to |
Object
|
<optional> |
Ending position. The keys of this Object should
match those of |
duration |
number
|
<optional> |
How many milliseconds to animate for. |
delay |
number
|
<optional> |
How many milliseconds to wait before starting the tween. |
start |
shifty.startFunction
|
<optional> |
Executes when the tween begins. |
render |
shifty.renderFunction
|
<optional> |
Executes on every tick. Legacy
property name: |
easing |
Object.<(string|shifty.easingFunction)>
|
string
|
shifty.easingFunction
|
<optional> |
Easing curve name(s) or |
data |
Object
|
<optional> |
Data that is passed to |
promise |
function
|
<optional> |
Promise constructor for when you want to use Promise library or polyfill Promises in unsupported environments. |
Type:
-
Object
tweenCreatedFilter(tweenable)
Is called when a tween is created. This should perform any setup needed by
subsequent per-tick calls to shifty.beforeTween
and shifty.afterTween
.
Parameters:
Name | Type | Description |
---|---|---|
tweenable |
shifty.Tweenable
|
The |