var Timeline = function(args){
var t = this, requiredType = 'Timeline';
if(t.type !== requiredType){
throw 'The ' + requiredType + ' Constructor must be invoked using the `new` keyword.';
}
args = args || {};
t.args = args;
t.frame = args.frame || 0;
t.totalFrames = args.totalFrames || 100;
t.keyframes = args.keyframes || [];
t.loop = args.loop || false;
t.calculateTweens();
return t;
};
Timeline.prototype = {
type: 'Timeline',//only for constructor checking
addKeyframe: function(k){this.keyframes.push(k);},
sortByKeyframeFrameNumber:function(a,b){return a.frame - b.frame;},
calculateTweens: function(){
var t = this, i, keyframe, keyframeObjectIdentifierString, propName, animatedProperty;
t.animatedProperties = {};
for(i = 0; i < t.keyframes.length; i += 1){ //iterate through keyframes and make sure that all properties something something
keyframe = t.keyframes[i];
keyframeObjectIdentifierString = keyframe.target._keyframeTargetIdentifier + '/' + keyframe.property;
if(!t.animatedProperties.hasOwnProperty(keyframeObjectIdentifierString)){
//assign the property to be an array, then assign a reference to that array to the animatedProperty var
animatedProperty = t.animatedProperties[keyframeObjectIdentifierString] = [];
//I am about to store a work state property on an array to help keep track of work yet to be done
animatedProperty.hasZeroKeyframeYet = false;
} else {
animatedProperty = t.animatedProperties[keyframeObjectIdentifierString];
}
animatedProperty.push(keyframe);
if(animatedProperty.frame === 0){
animatedProperty.hasZeroKeyframeYet = true;
}
}
for(propName in t.animatedProperties){
if(t.animatedProperties.hasOwnProperty(propName)){
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.