Tweenable Class
Tweenable constructor.
Constructor
Item Index
Methods
Properties
Methods
dispose
()
delete
all "own" properties. Call this when the Tweenable
instance
is no longer needed to free memory.
get
()
Object
Returns:
The current state.
interpolate
-
from
-
targetState
-
position
-
easing
-
opt_delay
Compute the midpoint of two Objects. This method effectively calculates a
specific frame of animation that tween
does many times over the course
of a full tween.
var interpolatedValues = Tweenable.interpolate({
width: '100px',
opacity: 0,
color: '#fff'
}, {
width: '200px',
opacity: 1,
color: '#000'
}, 0.5);
console.log(interpolatedValues);
// {opacity: 0.5, width: "150px", color: "rgb(127,127,127)"}
Parameters:
-
from
ObjectThe starting values to tween from.
-
targetState
ObjectThe ending values to tween to.
-
position
NumberThe normalized position value (between
0.0
and1.0
) to interpolate the values betweenfrom
andto
for.from
represents0
andto
represents1
. -
easing
Object.| String | Function The easing curve(s) to calculate the midpoint against. You can reference any easing function attached to
Tweenable.prototype.formula
, or provide the easing function(s) directly. If omitted, this defaults to "linear". -
opt_delay
Number=Optional delay to pad the beginning of the interpolated tween with. This increases the range of
position
from (0
through1
) to (0
through1 + opt_delay
). So, a delay of0.5
would increase all valid values ofposition
to numbers between0
and1.5
.
Returns:
isPlaying
()
Boolean
Returns:
Whether or not a tween is running.
pause
()
chainable
Pause a tween. Paused tweens can be resumed from the point at which they
were paused. This is different from stop
, as that method
causes a tween to start over when it is resumed.
resume
()
chainable
Resume a paused tween.
seek
-
millisecond
Move the state of the animation to a specific point in the tween's
timeline. If the animation is not running, this will cause the step
handlers to be called.
Parameters:
-
millisecond
MillisecondThe millisecond of the animation to seek to. This must not be less than
0
.
set
-
state
Parameters:
-
state
ObjectThe current state.
setBezierFunction
-
name
-
x1
-
y1
-
x2
-
y2
Create a Bezier easing function and attach it to Tweenable#formula
. 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
StringThe name of the easing curve. Overwrites the old easing function on
Tweenable#formula
if it exists. -
x1
Number -
y1
Number -
x2
Number -
y2
Number
Returns:
The easing function that was attached to Tweenable.prototype.formula.
setConfig
-
config
Configure a tween that will start at some point in the future.
Parameters:
-
config
ObjectThe following values are valid:
- from (Object=): Starting position. If omitted,
get()
is used. - to (Object=): Ending position.
- duration (number=): How many milliseconds to animate for.
- delay (delay=): How many milliseconds to wait before starting the tween.
- start (Function(Object, *)): Function to execute when the tween
begins. Receives the state of the tween as the first parameter and
attachment
as the second parameter. - step (Function(Object, *, number)): Function to execute on every
tick. Receives
get()
as the first parameter,attachment
as the second parameter, and the time elapsed since the start of the tween as the third. This function is not called on the final step of the animation, butfinish
is. - finish (Function(Object, *)): Function to execute upon tween
completion. Receives the state of the tween as the first parameter and
attachment
as the second parameter. - easing (Object.
|string|Function= ): Easing curve name(s) or function(s) to use for the tween. - attachment (*): Cached value that is passed to the
step
/start
/finish
methods.
- from (Object=): Starting position. If omitted,
setScheduleFunction
-
scheduleFunction
Set a custom schedule function.
If a custom function is not set,
requestAnimationFrame
is used if available, otherwise
setTimeout
is used.
Parameters:
-
scheduleFunction
Function(Function,number)The function to be used to schedule the next frame to be rendered.
stop
-
gotoEnd
Stops and cancels a tween.
Parameters:
-
gotoEnd
Boolean=If
false
or omitted, the tween just stops at its current state, and thefinish
handler is not invoked. Iftrue
, the tweened object's values are instantly set to the target values, andfinish
is invoked.
tween
-
opt_config
Configure and start a tween.
Parameters:
-
opt_config
Object=Configuration object to be passed to
setConfig
.
unsetBezierFunction
-
name
delete
an easing function from Tweenable#formula
. 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
StringThe name of the easing function to delete.
Returns:
Properties
formula
Object(function)
This object contains all of the tweens available to Shifty. It is
extensible - simply attach properties to the Tweenable.prototype.formula
Object following the same format as linear
.
pos
should be a normalized number
(between 0 and 1).