new Sequence(transformationSetopt) → {Object}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
transformationSet |
Object |
<optional> |
An object defining an initial set of transformations to add to the sequence. The layout of this object is the same as used in the addTransformations method. |
- Source:
Returns:
- Type
- Object
Methods
addTransformations(transformationSet)
Terminology:
-A transformation is a single change applied over time to a single feature of a single object. Its properties include which object to modify and what feature of it will be altered, a start time and starting value, and end time and ending value. For instance, a transformation may represent changing the "width" style of a DIV element from "100px" at time 1000 to "200px" at time 2000.
-A sequence is a collection of transformations that are to be applied together as a group.
-A target object is anything that will be modified by a transformation (e.g., a DOM element or a JavaScript object).
-A target feature is the aspect of the target object that will be modified (e.g., for a DOM element this might be "width").
-A unit is an optional (initially defaults to null
) string appended to a calculated value when applying it to a target feature
(e.g., for a DOM style property this might be "px").
-A calculator is a function that looks at the start and end values of a target feature and calculates a current value to apply
based on the current distance along the timeline. Ordinarily this is set to one of the pre-defined calculator functions in the Concert.Calculators namespace
(initially defaulting to Concert.Calculators.Linear
), but can also be a custom function, as explained further below.
-An applicator is a function that takes the values computed by the calculator function and applies them to the target feature.
For instance, different applicators would be used for setting JavaScript object properties, DOM element styles, or SVG element attributes.
Ordinarily this is set to one of the pre-defined applicator functions in the Concert.Applicators namespace
(initially defaulting to Concert.Applicators.Property
), but can also be a custom function, as explained further below.
-An easing is a function which modifies the rate at which a transformation moves from beginning to end.
For instance, it may progress steadily from the start time to the end time, or it may accelerate and decelerate to make motion appear smoother.
Ordinarily this is set to one of the pre-defined easing functions in the Concert.EasingFunctions namespace
(initially defaulting to Concert.EasingFunctions.ConstantRate
) but can also be a custom function, as explained further below.
Note: The easing function could easily be confused with the calculator function, because many animation libraries combine these two concepts. Here, however, they can be set independently. Essentially, a calculator function, given a start value, an end value, and the current time (in the form of a fractional distance between the start time and end time of the transformation), calculates a current value to apply. The easing function is what computes the current time that will be passed into the calculator function, allowing the rate at which a transformation proceeds to change over time. The reason for separating these becomes apparent when we consider that different types of calculation are necessary for different types of features. A function calculating an animated transition from one RGB color value to another uses a different algorithm than one calculating the animation of a simple, numeric value, for instance, or a complex calculator function that takes multiple inputs and calculates rotational movement. Because Concert.js allows anything at all to be animated, it supports the ability to choose any method of calculating values, and then (regardless of which one is used) specifying any easing function to alter the rate at which the animation takes place. Easing functions are specified at the level of the transformation (not the full sequence, although it is possible to set a default easing function for a sequence), so a single sequence can contain different transformations using a different easing functions.
Parameters:
Name | Type | Description |
---|---|---|
transformationSet |
Object | An object or array describing a set of changes which will be applied at specified times to specified target objects.
(A target object being anything that will be modified by the sequence, such as a DOM element or a JavaScript object.)
The transformationSet parameter is either a single object whose properties define a set of transformations, or an array of such objects.
Certain of the properties (as indicated below) are optional, and each sequence maintains its own settings for what default values will be applied to transformations
when the optional properties are not defined. (Note: these defaults are applied at the time the transformations are added, not at run-time, so changing the defaults
for a sequence will never alter transformations which have already been added to that sequence.)Important note: Adding two animation segments that overlap in time, and both try to modify the same feature of the same target object, produces undefined behavior. The expected layout of the object passed into this method is defined as follows (also see examples below): transformationSet = TransformationsObject OR transformationSet = [ TransformationsObject1, TransformationsObject2, ...] TransformationsObject = { target: TargetObjectDefinition, AND/OR targets: [ TargetObjectDefinition1, TargetObjectDefinition2, ...], feature: FeatureDefinition, // If absent, uses sequence's default value [unit: UnitDefinition,] // If absent, uses sequence's default value [applicator: ApplicatorFunction,] // If absent, uses sequence's default value [calculator: CalculatorFunction,] [calculatorModifiers: CalculatorModifiersObject,] // If absent, uses sequence's default value [easing: EasingFunction,] [userProperties: UserPropertiesObject,] keyframes: KeyframesDefinition OR segments: SegmentDefinition OR [ SegmentDefinition1, SegmentDefinition2, ...] };
{ [multiply: multiplicationFactorValue,] [modulo: moduloFactorValue,] [roundFactor: roundFactorValue,] [offset: offsetValue,] }These options are modifiers to the animation calculation engine, applied in the following ways and in the following order:
Rotational calculator (see Concert.Calculators)
is being used (i.e., when this transformation is animating rotational motion),
the object should be of the form:
{ [centerX: CalculatorModifiersObject,] [centerY: CalculatorModifiersObject,] [radius:CalculatorModifiersObject,] [angle: CalculatorModifiersObject,] [offsetX: CalculatorModifiersObject,] [offsetY: CalculatorModifiersObject] }Each individual CalculatorModifiersObject specified is an object of the form described above
(an object with some or all of these properties: multiply, modulo, roundFactor, offset).
This allows a separate set of modifiers to be applied to each of the values that can be animated in a
rotational transformation. For instance, the angle could be rounded to the nearest multiple of a number.
A very common use case would be specifying an offset so that the center of an element is what is rotated
around the specified center point rather than its upper left corner.
KeyframesDefinition = { times: KeyframeTimesArray, [values: KeyframeValuesArray] OR [valueGenerators: ValueGeneratorsArray] }; SegmentDefinition = { // Start time of this transformation t0: TimeDefinition, // End time: must be >= t0. t1: TimeDefinition, // Value applied at the start time v0: ValueDefinition, // Value applied at the end time v1: ValueDefinition, // OR // // Function to calculate v0 v0Generator: ValueGenerator, // Function to calculate v1 v1Generator: ValueGenerator, // If absent, falls back to the calculator // defined at the TransformationsObject // level; if also absent there, to the // sequence's default calculator. [calculator: CalculatorFunction,] // If absent, falls back to the // calculatorModifiers object defined // at the TransformationsObject level; // if also absent there, to the sequence's // default calculatorModifiers object. [calculatorModifers: CalculatorModifiersObject,] // If absent, falls back to easing function // defined at the TransformationsObject // level; if also absent there, to the // sequence's default easing. [easing: EasingFunction,] // If absent, falls back to the unit defined // at the TransformationsObject level; // if also absent there, to the sequence's // default unit. [unit: UnitDefinition,] // If absent, falls back to userProperties // object defined at the // TransformationsObject level; // if also absent there, to the sequence's // default userProperties object. [userProperties: userPropertiesObject] };
|
- Source:
Examples
sequence.addTransformations({
target: document.getElementById("someObject"),
feature: "left",
unit: "px",
applicator: Concert.Applicators.Style,
calculator: Concert.Calculators.Linear,
easing: Concert.EasingFunctions.ConstantRate,
keyframes: { times: [1000, 2000], values: [0, 60] }
});
sequence.setDefaults(
{
applicator: Concert.Applicators.Style,
calculator: Concert.Calculators.Linear,
easing: Concert.EasingFunctions.ConstantRate,
unit: "px"
});
sequence.addTransformations(
[
{
target: document.getElementById("someObject1"),
feature: ["left", "top"],
keyframes: { times: [0, 1000], values: [[0, 0], [100, 200]] }
},
{
target: document.getElementById("someObject2"),
feature: "width",
segments:
[
{ t0: 0, t1: 500, v0: 75, v1: 150 },
{ t0: 500, t1: 1000, v0: 150, v1: 75 },
]
}
]);
sequence.setDefaults(
{
applicator: Concert.Applicators.Style,
calculator: Concert.Calculators.Linear,
easing: Concert.EasingFunctions.QuadIn,
unit: "px"
});
sequence.addTransformations(
{
target: document.getElementById("PhotonTorpedoBox"),
feature: "left",
segments:
[{
t0: 0,
t1: 1000,
v0Generator:
function ()
{
var ship = document.getElementById("SpaceshipBox");
return (ship.offsetLeft + ship.offsetWidth);
},
v1Generator:
function ()
{
var ship = document.getElementById("SpaceshipBox");
return (ship.offsetLeft + ship.offsetWidth + 1000);
}
}]
});
// ... sometime later:
sequence.generateValues();
sequence.addTransformations(
{
target: document.getElementById("PhotonTorpedoBox"),
feature: "left",
keyframes:
{
times: [0, 1000],
valueGenerators:
[
function ()
{
var ship = document.getElementById("SpaceshipBox");
return (ship.offsetLeft + ship.offsetWidth);
},
function ()
{
var ship = document.getElementById("SpaceshipBox");
return (ship.offsetLeft + ship.offsetWidth + 1000);
}
]
}
});
function customApplicator(target, feature, value, unit)
{
target.each(function () { $(this).css(feature, value + unit); });
}
function customCalculator(distanceFraction, startValue,
endValue, addlProperties)
{
var outerBoxWidth = $("#OuterBox").innerWidth(),
calculatedValue =
(distanceFraction
* (endValue - startValue) * outerBoxWidth);
return calculatedValue;
}
function customEasing(startTime, endTime, currentTime)
{
var fractionComplete =
(currentTime - startTime) / (endTime - startTime);
if (fractionComplete < 2 / 3)
return (fractionComplete / 2);
else
return (1 / 3 + 2 * (fractionComplete - 2 / 3));
}
sequence.addTransformations(
{
target: $(".InnerBox"),
feature: "width",
applicator: customApplicator,
calculator: customCalculator,
easing: customEasing,
unit: "px",
keyframes:
{
times: [0, 1000],
values: [0, 0.5]
}
});
begin(parametersopt)
{ synchronizeTo: null, initialSeek: 0, timeOffset: null, autoStopAtEnd: true }
. Note that these parameter values can still be overridden, or any of the other parameters
accepted by the run method can be specified in the parameters
argument passed into this method.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
parameters |
Object |
<optional> |
An object with property values setting options for how to run the sequence. See the run method for information on allowable properties and values in this object. |
- Source:
clone(targetLookupFunction, matchRunningStatusopt, doInitialSeekopt) → {Object}
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
targetLookupFunction |
function | A function taking a single parameter. The value passed in will be one of the transformation targets of the original sequence. The function must return the equivalent object which should be targeted by the equivalent transformation in the new sequence. | ||
matchRunningStatus |
boolean |
<optional> |
false | If true , and the sequence being cloned is currently running, the new sequence will jump to the same point on the timeline and run as well. Otherwise, the new sequence will not automatically start running. |
doInitialSeek |
boolean |
<optional> |
false | If true , the new sequence will immediately seek to the same point on the timeline as the original sequence. Otherwise, the new sequence will merely be created, but will not immediately perform any action (unless the matchRunningStatus parameter is true ). |
- Source:
Returns:
targetLookupFunction
parameter.
- Type
- Object
Example
var originalSequence = new Concert.Sequence();
originalSequence.setDefaults(
{
applicator: Concert.Applicators.Style,
calculator: Concert.Calculators.Linear,
easing: Concert.EasingFunctions.ConstantRate,
unit: "px"
});
originalSequence.addTransformations(
[
{
target: "UpperElement", feature: "left",
keyframes: { times: [0, 1000], values: [100, 200] }
},
{
target: "LowerElement", feature: "left",
keyframes: { times: [0, 1000], values: [100, 200] }
}
]);
//...some time later, having created DOM elements with id values
// like "UpperElement1", "LowerElement1", "UpperElement2", ...
var newSequence1 = originalSequence.clone(
function (originalTarget)
{ return document.getElementById(originalTarget + "1"); });
var newSequence2 = originalSequence.clone(
function (originalTarget)
{ return document.getElementById(originalTarget + "2"); });
follow(syncSource, parametersopt)
follow
causes the sequence to run exactly in time with the synchronization source and in the same direction, but starting at the current timeline position, whereas
with syncTo the sequence will first jump to a timeline position matching the current value of the synchronization source and then do the same.
This is really just a shortcut method provided for a common usage scenario; it is exactly the same as calling the run method with the parameters
{ synchronizeTo: syncSource, initialSeek: null, timeOffset: null }
. Note that these parameter values can still be overridden, or any of the other parameters
accepted by the run method can be specified in the parameters
argument passed into this method.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
syncSource |
Varies | A synchronization source. Can take any of the following different types of values:
|
|
parameters |
Object |
<optional> |
An object with property values setting options for how to run the sequence. See the run method for information on allowable properties and values in this object. |
- Source:
generateValues()
It may be useful at times to define transformations whose start and end values are not fixed at the time the transformations are first defined, but which instead are calculated dynamically at some later time prior to running the sequence. This is accomplished by specifying functions instead of start and end values, as explained in the documentation for the addTransformations method. Those functions (for all such transformations in a sequence) are then called, and their return values stored as the start and end values of their respective transformations, either at the time the sequence is run by specifying the appropriate option when calling the run, begin, follow, or syncTo methods, or at any time by calling
generateValues
.
- Source:
getCurrentTime() → {number}
- Source:
Returns:
- Type
- number
getEndTime() → {number}
- Source:
Returns:
- Type
- number
getID() → {number}
- Source:
Returns:
- Type
- number
getStartTime() → {number}
- Source:
Returns:
- Type
- number
index(completionCallback, isAsynchronous)
Explanation of Indexing: Concert.js sequences can consist of very large numbers of transformations applied to numerous target objects, with the ability to seek extremely quickly to any point in the sequence. This is what makes it useful for synchronizing to other things (such as audio or video) and for other situations that require arbitrary seeking, running at different speeds or in either direction, or other uses that don't conform to a simple, run-once-forward-only-at-normal-speed scenario. What makes this possible is an internal data structure that optimizes for quickly finding the correct value to apply to every target feature of every one of the objects being animated, at any point along the timeline. This internal structure involves a set of pre-built indexes of timeline segments. Much like indexes on database tables, this vastly speeds up run-time lookup performance by doing some processing ahead of time to analyze and organize the data. Every sequence needs to be indexed once (or again after any new transformations are added). Running or seeking to any point in an un-indexed sequence will cause indexing to take place automatically, or indexing can be run manually with this method. In many cases, the automatic indexing will run fast enough that manually running the indexer is not necessary.
Parameters:
Name | Type | Description |
---|---|---|
completionCallback |
function | This function will be executed upon completion of indexing. It is especially useful if the isAsynchronous
parameter is set to true . The function specified here should have a signature of the form someCallBackFunction(sequenceObject) .
That is, the function will be called with a single argument, which will be the sequence object whose indexing has completed. (For purposes of handling this
callback when there are multiple sequences being manipulated, it may also be helpful to remember that every Sequence object has a
unique integer ID which can be retrieved using the getID method.) |
isAsynchronous |
boolean | If true , the indexing process will not be run all at once, but will instead be broken into
smaller chunks of work and scheduled using calls to window.setTimeout . This is useful for very large sequences, to help reduce
or eliminate any noticable pause in browser responsiveness while indexing is taking place.For the current version, the indexer makes a best effort to keep each processing chunk under 100 ms. Future versions may allow the programmer to adjust this value, and may also be able to incorporate web workers as a way of pushing most of the work into a completely separate, concurrent thread. |
- Source:
isRunning() → {boolean}
- Source:
Returns:
true
if the sequence is currently running, false
otherwise.
- Type
- boolean
retarget(targetLookupFunction)
Parameters:
Name | Type | Description |
---|---|---|
targetLookupFunction |
function | A function that, when passed a transformation target from the sequence as currently defined, returns the new object to be targeted. |
- Source:
run(parametersopt)
parameters
object.
For many purposes, one of the other run methods (begin, follow, or syncTo)
may be easier, because they assume certain default options that are correct in most usage scenarios, but this method is the general-purpose way to run a sequence
with any set of behavioral options, and is in fact used behind the scenes by those other methods. Except for generateValues
, initialSeek
, and
timeOffset
(the last of which is automatically re-calculated if null), options specified in the parameters
object are remembered and will be retained
as the default values. This means for restarting stopped sequences, it is not always necessary to explicitly re-state all the options, and it also means that this method can be
called on an already-running sequence to change run-time options on the fly.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
parameters |
Object |
<optional> |
An object with property values setting options for how to run the sequence.
Defined as follows below. Any or all of the below options may be specified:
|
- Source:
seek(time, useSoleControlOptimizationopt)
time
value is less than the sequence's start time or greater than the sequence's end time,
the resulting behavior will be defined by the sequence's "before" or "after" repeating behavior settings,
as controlled by the setBefore and setAfter methods
or by the options passed into the run, begin,
follow, or syncTo methods.
The default behavior, if none has explicitly been specified, is Concert.Repeating.None,
which seeks to the sequence start time for any time
value less than or equal to the sequence's
start time, and to the end time for any time
value greater than or equal to the sequence's end time.
The useSoleControlOptimization
option, when set to true, enhances run-time performance,
but should only be used if nothing other than the Concert sequence will be modifying any target object properties
that are modified by transformations in the sequence. Essentially it skips updating target object properties
any time a newly calculated value is the same as the last one applied. This speeds up seek times,
especially when doing relatively slow things such as DOM updates. However, if a target object property's value
has been changed by something else since the last time the sequence object touched it, this optimization
can result in that value not being updated by the seek() function.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
time |
number | The intended seek point. | |
useSoleControlOptimization |
boolean |
<optional> |
Whether or not the sequence can optimize by assuming sole control over the target objects. |
- Source:
setAfter(newAfter)
Parameters:
Name | Type | Description |
---|---|---|
newAfter |
function | One of the functions defined in Concert.Repeating, or a custom function.
For any sequence where this is not explicitly set, the "after" behavior defaults to Concert.Repeating.None .
Any function passed in here should have a signature of the form function (sequenceStart, sequenceEnd, unadjustedTime) and must return
an object of the form { adjustedTime: XXX, hitFinalBoundary: YYY } , where XXX is the actual time to use in the seek, and
YYY is a boolean value indicating whether this seek will put the sequence at one of its final boundary points. For instance, a looping
behavior function could take an unadjustedTime value past the end of the sequence and map it to a resulting value somewhere between the
sequence start and end times, and if it does not loop infinitely, a high enough input would result in hitting the final boundary beyond which looping
does not continue. The hitFinalBoundary property value is what is used to determine whether to automatically call the
stop method if running with autoStopAtEnd set to true . |
- Source:
setBefore(newBefore)
Parameters:
Name | Type | Description |
---|---|---|
newBefore |
Object | One of the functions defined in Concert.Repeating, or a custom function.
For any sequence where this is not explicitly set, the "after" behavior defaults to Concert.Repeating.None .
Any function passed in here should have a signature of the form function (sequenceStart, sequenceEnd, unadjustedTime) and must return
an object of the form { adjustedTime: XXX, hitFinalBoundary: YYY } , where XXX is the actual time to use in the seek, and
YYY is a boolean value indicating whether this seek will put the sequence at one of its final boundary points. For instance, a looping
behavior function could take an unadjustedTime value past the end of the sequence and map it to a resulting value somewhere between the
sequence start and end times, and if it does not loop infinitely, a high enough input would result in hitting the final boundary beyond which looping
does not continue. The hitFinalBoundary property value is what is used to determine whether to automatically call the
stop method if running with autoStopAtEnd set to true . |
- Source:
setDefaults(newDefaults)
Parameters:
Name | Type | Description |
---|---|---|
newDefaults |
Object | An object with property values setting default options for new transformations. Defined as follows.
Any or all of the below options may be specified.
|
- Source:
stop()
autoStopAtEnd
to true
,
is recommended when you wish the sequence to stop running or synchronizing, because otherwise the timers which continually update the sequence will continue to run.
This may be the desired behavior if the sequence is being synchronized to a value which may continue to change, but in many cases it would be a waste of processor
cycles to continue running a completed sequence. (Note that autoStopAtEnd
is automatically enabled if the sequence is run using the
begin method.)
- Source:
syncTo(syncSource, parametersopt)
syncTo
the sequence will first jump to a timeline position matching the current value of the synchronization source and then do the same.
This is really just a shortcut method provided for a common usage scenario; it is exactly the same as calling the run method with the parameters
{ synchronizeTo: syncSource, initialSeek: null, timeOffset: 0, autoStopAtEnd: false }
. Note that these parameter values can still be overridden,
or any of the other parameters accepted by the run method can be specified in the parameters
argument passed into this method.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
syncSource |
Varies | A synchronization source. Can take any of the following different types of values:
|
|
parameters |
Object |
<optional> |
An object with property values setting options for how to run the sequence. See the run method for information on allowable properties and values in this object. |
- Source: