Skip to content

Commit 78f5251

Browse files
committed
Updated preloaded animations and added a few comments
1 parent 4f2d953 commit 78f5251

File tree

2 files changed

+72
-33
lines changed

2 files changed

+72
-33
lines changed

animateText.js

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
1717
function AnimateText(element, textObjects, options, animations){
1818
var self = this;
1919

20-
this.$element = $(element);
20+
this.$element = $(element); //ul jQuery object
2121
this.textObjects = textObjects;
22-
this.lastTextObject;
23-
this.repeated = 0;
22+
this.lastTextObject; //last text object to complete its animation
23+
this.repeated = 0; //# of times the animation sequence has repeated
2424

2525
//Default options
2626
this.defaults = {
2727
repeat: true,
2828
element: {
2929
css: {
3030
position: 'relative',
31+
overflow: 'hidden',
3132
margin: 0,
3233
padding: 0,
3334
width: function(){
@@ -50,7 +51,7 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
5051
},
5152
position: {
5253
duration: 1000,
53-
easing: 'linear'
54+
easing: 'swing'
5455
}
5556
};
5657

@@ -62,81 +63,99 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
6263
"fadeIn": {
6364
positions: {
6465
start: {
65-
opacity:0
66+
top: '50%',
67+
left: '50%',
68+
opacity: 0
6669
},
6770
0: {
68-
opacity:1
71+
opacity: 1,
72+
duration: 1200
73+
},
74+
1: {
75+
duration: 1200
76+
},
77+
2: {
78+
opacity: 0,
79+
duration: 300
6980
}
7081
}
7182
},
7283
"fadeOut": {
7384
positions: {
7485
start: {
75-
opacity:1
86+
top: '50%',
87+
left: '50%',
88+
opacity: 1
7689
},
7790
0: {
78-
opacity:0
91+
duration: 1200
92+
},
93+
1: {
94+
opacity: 0
7995
}
8096
}
8197
},
82-
"right_to_left": {
98+
"rightToLeft": {
8399
positions: {
84100
start: {
85-
right: 0,
101+
width: '100%',
102+
left: '100%',
86103
opacity: 0,
87-
top: '50%'
104+
top: '50%',
105+
'text-align': 'left'
88106
},
89107
0: {
90-
right: '75%',
108+
left: '25%',
91109
opacity: 1,
92-
duration:600
110+
duration: 1200
93111
},
94112
1: {
95-
duration:600
113+
duration: 1200
96114
},
97115
2: {
98116
opacity: 0,
99-
duration:600
117+
duration: 1200
100118
}
101119
}
102120
},
103-
"left_to_right": {
121+
"leftToRight": {
104122
positions: {
105123
start: {
124+
width: '100%',
106125
right: '100%',
107126
opacity: 0,
108-
'text-align': 'right',
109127
top: '50%',
128+
'text-align': 'right'
110129
},
111130
0: {
112131
right: '25%',
113132
opacity: 1,
114-
duration: 600
133+
duration: 1200
115134
},
116135
1: {
117-
duration: 600
136+
duration: 1200
118137
},
119138
2: {
120139
opacity: 0,
121-
duration: 600
140+
duration: 1200
122141
}
123142
}
124143
},
125144
"explode": {
126145
positions: {
127146
start: {
128-
top: '30%',
147+
top: '40%',
129148
width: '100%',
130149
opacity: 0,
131150
'font-size': '10px',
132151
'text-align': 'center'
133152
},
134153
0: {
135-
opacity:1,
136-
duration:0
154+
opacity: 1,
155+
duration: 0
137156
},
138157
1: {
139-
top: '0%',
158+
top:'-10%',
140159
'font-size': '150px',
141160
opacity: 0,
142161
duration: 1000
@@ -147,7 +166,7 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
147166
positions: {
148167
start: {
149168
width: '100%',
150-
opacity:0,
169+
opacity: 0,
151170
top: '0%',
152171
'font-size': '150px',
153172
'text-align': 'center'
@@ -157,6 +176,13 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
157176
'font-size': '40px',
158177
opacity: 1,
159178
duration: 1000
179+
},
180+
1: {
181+
duration: 1200
182+
},
183+
2: {
184+
opacity: 0,
185+
duration: 400
160186
}
161187
}
162188
}
@@ -175,6 +201,7 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
175201
//Hide ul element and set css
176202
this.$element.hide().css(this.options.element.css);
177203

204+
//Start animation as soon as animations and textObjects are loaded.
178205
this.loadAnimations();
179206
this.loadTextObjects(function(){
180207
self.$element.show();
@@ -185,19 +212,23 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
185212
loadAnimations: function(){
186213
var self = this;
187214

215+
//Validate every position in every animation
188216
$.each(this.animations, function(animationId, animation){
189217
animation.duration = 0;
190218

191219
$.each(animation.positions, function(positionId, position){
192220
if(positionId !== "start"){
221+
//Make sure position's duration is set
193222
if(typeof(position.duration) !== "number" || position.duration < 0){
194223
position.duration = self.options.position.duration;
195224
}
196225

226+
//Make sure position's easing property is set
197227
if(typeof(position.easing) === "undefined"){
198228
position.easing = self.options.position.easing;
199229
}
200230

231+
//Calculate the animation's total duration
201232
animation.duration += position.duration;
202233
}
203234
});
@@ -207,8 +238,10 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
207238
loadTextObjects: function(callback){
208239
var self = this;
209240

241+
//Keep track of the animation sequence's total duration
210242
totalDuration = 0;
211243

244+
//Validate every textObject
212245
$.each(this.textObjects, function(textObjectId, textObject){
213246
var textObjectDuration = 0;
214247

@@ -222,6 +255,7 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
222255
return;
223256
}
224257

258+
//Set textObject to its default style
225259
textObject.$element.css(self.options.textObject.css).attr('id', textObject.id);
226260

227261
//Check for valid animation type
@@ -238,8 +272,10 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
238272
textObject.duration = 0;
239273
}
240274

275+
//Merge textObject's positions with its animation's positions
241276
textObject.positions = $.extend(true, {}, self.animations[textObject.animation].positions, textObject.positions);
242277

278+
//Calculate textObject duration
243279
$.each(textObject.positions, function(positionId, position){
244280
if(positionId !== "start"){
245281
if(typeof(textObject.duration) === "number" && textObject.duration > 0){
@@ -255,7 +291,7 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
255291
textObject.duration = textObjectDuration;
256292
}
257293

258-
//Calculate text object duration
294+
//Determine if this textObject will be last to complete its animation
259295
if((textObject.offset + textObject.duration) > totalDuration){
260296
totalDuration = (textObject.offset + textObject.duration);
261297
self.lastTextObject = textObject.id;
@@ -274,6 +310,7 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
274310
//Set textObject to its start position
275311
textObject.$element.css(textObject.positions.start);
276312

313+
//Start textObject's animation after it's offset time has passed
277314
setTimeout(function(){
278315
self.animateTextObject(textObject.id, 0);
279316
}, textObject.offset);
@@ -287,8 +324,14 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
287324
animateTextObject: function(textObjectId, animationPosition){
288325
var self = this,
289326
textObject = this.textObjects[textObjectId],
290-
animation = this.animations[textObject.animation];
291-
327+
animation = this.animations[textObject.animation],
328+
test = function(){
329+
var to = textObject;
330+
console.log(to);
331+
return 'hey';
332+
};
333+
334+
//Finally, animate the textObject
292335
textObject.$element.animate(
293336
textObject.positions[animationPosition],
294337
textObject.positions[animationPosition].duration,
@@ -304,13 +347,9 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
304347

305348
//Repeat animations if repeat option is set to true or we're still under the set repeat limit
306349
if(self.options.repeat === true || (typeof(self.options.repeat) === "number" && self.repeated < self.options.repeat)){
307-
self.stopAnimation();
308350
self.startAnimation();
309351
self.repeated++;
310352
}
311-
else{
312-
self.stopAnimation();
313-
}
314353
}
315354
}
316355
);

animateText.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)