Classes
Methods
(static) interpolate(from, to, position, easing, delayopt) → {T}
Compute the midpoint of two Objects. This method effectively calculates a
specific frame of animation that 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 |
T
|
The starting values to tween from. |
||
to |
T
|
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:
-
T
(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 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 Tweenable.setScheduleFunction
, override 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 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 Tweenable.formulas
.
(static) shouldScheduleUpdate(doScheduleUpdate)
Determines whether or not a heartbeat tick should be scheduled. This is generally only useful for testing environments where Shifty's continuous heartbeat mechanism causes test runner issues.
If you are using Jest, you'll want to put this in a global afterAll
hook.
If you don't already have a Jest setup file, follow the setup in this
StackOverflow post, and then add this
to it:
import { shouldScheduleUpdate } from 'shifty'
afterAll(() => {
shouldScheduleUpdate(false)
})
Parameters:
Name | Type | Description |
---|---|---|
doScheduleUpdate |
boolean
|
(static) tween(configopt) → {Tweenable}
Standalone convenience method that functions identically to
Tweenable#tween
. You can use this to create tweens without
needing to set up a 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> |
{} |
(static) unsetBezierFunction(name) → {boolean}
delete
an easing function from 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) → {void}
Is called right after a tween is processed in a tick.
Parameters:
Name | Type | Description |
---|---|---|
tweenable |
Tweenable
|
The |
Returns:
- Type:
-
void
beforeTweenFilter(tweenable) → {void}
Is called right before a tween is processed in a tick.
Parameters:
Name | Type | Description |
---|---|---|
tweenable |
Tweenable
|
The |
Returns:
- Type:
-
void
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 |
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
finishFunction(promisedData) → {void}
Parameters:
Name | Type | Description |
---|---|---|
promisedData |
shifty.promisedData
|
Returns:
- Type:
-
void
promisedData
Properties:
Name | Type | Description |
---|---|---|
state |
Object
|
The current state of the tween. |
data |
Object
|
The |
tweenable |
Tweenable
|
The |
Type:
-
Object
renderFunction(state, data, timeElapsed) → {void}
Gets called for every tick of the tween. This function is not called on the final tick of the animation.
Parameters:
Name | Type | Description |
---|---|---|
state |
Object
|
The current state of the tween. |
data |
Object
|
undefined
|
User-defined data provided via a |
timeElapsed |
number
|
The time elapsed since the start of the tween. |
Returns:
- Type:
-
void
scheduleFunction(callback, timeout) → {void}
Parameters:
Name | Type | Description |
---|---|---|
callback |
function
|
|
timeout |
number
|
Returns:
- Type:
-
void
startFunction(state, dataopt) → {void}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
state |
Object
|
The current state of the tween. |
|
data |
Object
|
undefined
|
<optional> |
User-defined data provided via a |
Returns:
- Type:
-
void
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. |
finish |
shifty.finishFunction
|
<optional> |
Executes when the tween
completes. This will get overridden by |
render |
shifty.renderFunction
|
<optional> |
Executes on every tick. Shifty
assumes a retained mode
rendering environment, which in practice means that Legacy property name: |
easing |
string
|
shifty.easingFunction
|
Object.<(string|shifty.easingFunction)>
|
Array.<number>
|
<optional> |
You can learn more about this in the Easing Curves in Depth tutorial. |
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