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:
-
fromObjectThe starting values to tween from.
-
targetStateObjectThe ending values to tween to.
-
positionNumberThe normalized position value (between
0.0and1.0) to interpolate the values betweenfromandtofor.fromrepresents0andtorepresents1. -
easingObject.| 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_delayNumber=Optional delay to pad the beginning of the interpolated tween with. This increases the range of
positionfrom (0through1) to (0through1 + opt_delay). So, a delay of0.5would increase all valid values ofpositionto numbers between0and1.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:
-
millisecondMillisecondThe millisecond of the animation to seek to. This must not be less than
0.
set
-
state
Parameters:
-
stateObjectThe 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:
-
nameStringThe name of the easing curve. Overwrites the old easing function on
Tweenable#formulaif it exists. -
x1Number -
y1Number -
x2Number -
y2Number
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:
-
configObjectThe 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
attachmentas the second parameter. - step (Function(Object, *, number)): Function to execute on every
tick. Receives
get()as the first parameter,attachmentas 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, butfinishis. - finish (Function(Object, *)): Function to execute upon tween
completion. Receives the state of the tween as the first parameter and
attachmentas 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/finishmethods.
- 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:
-
scheduleFunctionFunction(Function,number)The function to be used to schedule the next frame to be rendered.
stop
-
gotoEnd
Stops and cancels a tween.
Parameters:
-
gotoEndBoolean=If
falseor omitted, the tween just stops at its current state, and thefinishhandler is not invoked. Iftrue, the tweened object's values are instantly set to the target values, andfinishis invoked.
tween
-
opt_config
Configure and start a tween.
Parameters:
-
opt_configObject=Configuration object to be passed to
setConfig.
unsetBezierFunction
-
name
delete an easing function from Tweenable#formula. Be
careful with this method, as it deletes whatever easing formula matches
name (which means you can delete standard Shifty easing functions).
Parameters:
-
nameStringThe 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).
