@@ -17,17 +17,18 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
17
17
function AnimateText ( element , textObjects , options , animations ) {
18
18
var self = this ;
19
19
20
- this . $element = $ ( element ) ;
20
+ this . $element = $ ( element ) ; //ul jQuery object
21
21
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
24
24
25
25
//Default options
26
26
this . defaults = {
27
27
repeat : true ,
28
28
element : {
29
29
css : {
30
30
position : 'relative' ,
31
+ overflow : 'hidden' ,
31
32
margin : 0 ,
32
33
padding : 0 ,
33
34
width : function ( ) {
@@ -50,7 +51,7 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
50
51
} ,
51
52
position : {
52
53
duration : 1000 ,
53
- easing : 'linear '
54
+ easing : 'swing '
54
55
}
55
56
} ;
56
57
@@ -62,81 +63,99 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
62
63
"fadeIn" : {
63
64
positions : {
64
65
start : {
65
- opacity :0
66
+ top : '50%' ,
67
+ left : '50%' ,
68
+ opacity : 0
66
69
} ,
67
70
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
69
80
}
70
81
}
71
82
} ,
72
83
"fadeOut" : {
73
84
positions : {
74
85
start : {
75
- opacity :1
86
+ top : '50%' ,
87
+ left : '50%' ,
88
+ opacity : 1
76
89
} ,
77
90
0 : {
78
- opacity :0
91
+ duration : 1200
92
+ } ,
93
+ 1 : {
94
+ opacity : 0
79
95
}
80
96
}
81
97
} ,
82
- "right_to_left " : {
98
+ "rightToLeft " : {
83
99
positions : {
84
100
start : {
85
- right : 0 ,
101
+ width : '100%' ,
102
+ left : '100%' ,
86
103
opacity : 0 ,
87
- top : '50%'
104
+ top : '50%' ,
105
+ 'text-align' : 'left'
88
106
} ,
89
107
0 : {
90
- right : '75 %' ,
108
+ left : '25 %' ,
91
109
opacity : 1 ,
92
- duration :600
110
+ duration : 1200
93
111
} ,
94
112
1 : {
95
- duration :600
113
+ duration : 1200
96
114
} ,
97
115
2 : {
98
116
opacity : 0 ,
99
- duration :600
117
+ duration : 1200
100
118
}
101
119
}
102
120
} ,
103
- "left_to_right " : {
121
+ "leftToRight " : {
104
122
positions : {
105
123
start : {
124
+ width : '100%' ,
106
125
right : '100%' ,
107
126
opacity : 0 ,
108
- 'text-align' : 'right' ,
109
127
top : '50%' ,
128
+ 'text-align' : 'right'
110
129
} ,
111
130
0 : {
112
131
right : '25%' ,
113
132
opacity : 1 ,
114
- duration : 600
133
+ duration : 1200
115
134
} ,
116
135
1 : {
117
- duration : 600
136
+ duration : 1200
118
137
} ,
119
138
2 : {
120
139
opacity : 0 ,
121
- duration : 600
140
+ duration : 1200
122
141
}
123
142
}
124
143
} ,
125
144
"explode" : {
126
145
positions : {
127
146
start : {
128
- top : '30 %' ,
147
+ top : '40 %' ,
129
148
width : '100%' ,
130
149
opacity : 0 ,
131
150
'font-size' : '10px' ,
132
151
'text-align' : 'center'
133
152
} ,
134
153
0 : {
135
- opacity :1 ,
136
- duration :0
154
+ opacity : 1 ,
155
+ duration : 0
137
156
} ,
138
157
1 : {
139
- top : '0 %',
158
+ top :'-10 %',
140
159
'font-size' : '150px' ,
141
160
opacity : 0 ,
142
161
duration : 1000
@@ -147,7 +166,7 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
147
166
positions : {
148
167
start : {
149
168
width : '100%' ,
150
- opacity :0 ,
169
+ opacity : 0 ,
151
170
top : '0%' ,
152
171
'font-size' : '150px' ,
153
172
'text-align' : 'center'
@@ -157,6 +176,13 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
157
176
'font-size' : '40px' ,
158
177
opacity : 1 ,
159
178
duration : 1000
179
+ } ,
180
+ 1 : {
181
+ duration : 1200
182
+ } ,
183
+ 2 : {
184
+ opacity : 0 ,
185
+ duration : 400
160
186
}
161
187
}
162
188
}
@@ -175,6 +201,7 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
175
201
//Hide ul element and set css
176
202
this . $element . hide ( ) . css ( this . options . element . css ) ;
177
203
204
+ //Start animation as soon as animations and textObjects are loaded.
178
205
this . loadAnimations ( ) ;
179
206
this . loadTextObjects ( function ( ) {
180
207
self . $element . show ( ) ;
@@ -185,19 +212,23 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
185
212
loadAnimations : function ( ) {
186
213
var self = this ;
187
214
215
+ //Validate every position in every animation
188
216
$ . each ( this . animations , function ( animationId , animation ) {
189
217
animation . duration = 0 ;
190
218
191
219
$ . each ( animation . positions , function ( positionId , position ) {
192
220
if ( positionId !== "start" ) {
221
+ //Make sure position's duration is set
193
222
if ( typeof ( position . duration ) !== "number" || position . duration < 0 ) {
194
223
position . duration = self . options . position . duration ;
195
224
}
196
225
226
+ //Make sure position's easing property is set
197
227
if ( typeof ( position . easing ) === "undefined" ) {
198
228
position . easing = self . options . position . easing ;
199
229
}
200
230
231
+ //Calculate the animation's total duration
201
232
animation . duration += position . duration ;
202
233
}
203
234
} ) ;
@@ -207,8 +238,10 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
207
238
loadTextObjects : function ( callback ) {
208
239
var self = this ;
209
240
241
+ //Keep track of the animation sequence's total duration
210
242
totalDuration = 0 ;
211
243
244
+ //Validate every textObject
212
245
$ . each ( this . textObjects , function ( textObjectId , textObject ) {
213
246
var textObjectDuration = 0 ;
214
247
@@ -222,6 +255,7 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
222
255
return ;
223
256
}
224
257
258
+ //Set textObject to its default style
225
259
textObject . $element . css ( self . options . textObject . css ) . attr ( 'id' , textObject . id ) ;
226
260
227
261
//Check for valid animation type
@@ -238,8 +272,10 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
238
272
textObject . duration = 0 ;
239
273
}
240
274
275
+ //Merge textObject's positions with its animation's positions
241
276
textObject . positions = $ . extend ( true , { } , self . animations [ textObject . animation ] . positions , textObject . positions ) ;
242
277
278
+ //Calculate textObject duration
243
279
$ . each ( textObject . positions , function ( positionId , position ) {
244
280
if ( positionId !== "start" ) {
245
281
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
255
291
textObject . duration = textObjectDuration ;
256
292
}
257
293
258
- //Calculate text object duration
294
+ //Determine if this textObject will be last to complete its animation
259
295
if ( ( textObject . offset + textObject . duration ) > totalDuration ) {
260
296
totalDuration = ( textObject . offset + textObject . duration ) ;
261
297
self . lastTextObject = textObject . id ;
@@ -274,6 +310,7 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
274
310
//Set textObject to its start position
275
311
textObject . $element . css ( textObject . positions . start ) ;
276
312
313
+ //Start textObject's animation after it's offset time has passed
277
314
setTimeout ( function ( ) {
278
315
self . animateTextObject ( textObject . id , 0 ) ;
279
316
} , textObject . offset ) ;
@@ -287,8 +324,14 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
287
324
animateTextObject : function ( textObjectId , animationPosition ) {
288
325
var self = this ,
289
326
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
292
335
textObject . $element . animate (
293
336
textObject . positions [ animationPosition ] ,
294
337
textObject . positions [ animationPosition ] . duration ,
@@ -304,13 +347,9 @@ Licensed under MIT License (https://github.com/jquery/jquery/blob/master/MIT-LIC
304
347
305
348
//Repeat animations if repeat option is set to true or we're still under the set repeat limit
306
349
if ( self . options . repeat === true || ( typeof ( self . options . repeat ) === "number" && self . repeated < self . options . repeat ) ) {
307
- self . stopAnimation ( ) ;
308
350
self . startAnimation ( ) ;
309
351
self . repeated ++ ;
310
352
}
311
- else {
312
- self . stopAnimation ( ) ;
313
- }
314
353
}
315
354
}
316
355
) ;
0 commit comments