new EaseMachine(fc, ms [, startValues] [, endValues])
A simple device to make ease functions easy to use. Requests a cubic function that takes the
form function (t, b, c, d)
, where:
- t = current time
- b = starting value
- c = change in value
- d = duration
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
fc |
function | string | The cubic function or the function name of a static method. |
|
ms |
number | Milliseconds to perform the function. |
|
startValues |
Object.<string, number> | number |
<optional> |
Name/value pairs of starting values, or a single value. |
endValues |
Object.<string, number> | number |
<optional> |
Name/value pairs of ending values, or a single value. |
- Since:
-
8.6.0 Allow the static function name to be passed instead of the function itself.
Example
let e = new CIQ.EaseMachine("easeInOutCubic", 200);
e.run(function(v){console.log(v)}, 100, 110);
Members
-
hasCompleted :boolean
-
This will be false while the ease machine is completing
Type:
- boolean
Methods
-
reset(startValues, endValues)
-
Resets the ease machine with a new set of values.
Parameters:
Name Type Description startValues
Object.<string, number> | number Name/value pairs of starting values, or a single value. If null, the
endValues
become thestartValues
(allowing for resetting or reversing of direction).endValues
Object.<string, number> | number Name/value pairs of ending values, or a single value.
-
run(fc [, startValues] [, endValues] [, delayFirstRun] [, ownerWindow])
-
Runs the ease machine in a loop until completion by calling
next()
from within arequestAnimationFrame
.Parameters:
Name Type Argument Default Description fc
function Function callback which receives the results of CIQ.EaseMachine#next.
startValues
Object.<string, number> | number <optional>
Name/value pairs of starting values, or a single value.
endValues
Object.<string, number> | number <optional>
Name/value pairs of ending values, or a single value.
delayFirstRun
boolean <optional>
false Normally, the first pass of the run happens immediately. Pass true if you want to wait for the next animation frame before beginning.
ownerWindow
object <optional>
The window where the parent chart is loaded. This resolves the known MDN issue where the requestAnimationFrame callback is never called when the parent window is hidden (background page).
- Since:
-
8.9.1 Added
ownerWindow
parameter.
-
stop( [ownerWindow])
-
Stops the ease machine from running mid-animation. Returns the current state.
Parameters:
Name Type Argument Description ownerWindow
object <optional>
The window where the parent chart is loaded. This resolves the known MDN issue where the requestAnimationFrame callback is never called when the parent window is hidden (background page).
- Since:
-
8.9.1 Added
ownerWindow
parameter.
Returns:
Name/value pairs of current values, or the current value.
- Type
- Object.<string, number>
-
easeInOutCubic(t, b, c, d)
-
Cubic easing in/out - acceleration until halfway, then deceleration (https://gizma.com/easing/).
Parameters:
Name Type Description t
number Current time (t should move from zero to d).
b
number Starting value.
c
number Change in value (b + c = ending value ).
d
number Duration.
- Since:
-
8.6.0
-
easeInOutQuad(t, b, c, d)
-
Quadratic easing out - decelerating to zero velocity (https://gizma.com/easing/).
Parameters:
Name Type Description t
number Current time (t should move from zero to d).
b
number Starting value.
c
number Change in value (b + c = ending value ).
d
number Duration.
- Since:
-
8.6.0
-
easeOutCubic(t, b, c, d)
-
Cubic easing out - decelerating to zero velocity (https://gizma.com/easing/).
Parameters:
Name Type Description t
number Current time (t should move from zero to d).
b
number Starting value.
c
number Change in value (b + c = ending value ).
d
number Duration.
- Since:
-
8.6.0