1
+ /* global $, window, document, snabbt, Hammer, FastClick*/
2
+ 'use strict' ;
1
3
$ ( function ( ) {
2
4
3
- var title = $ ( "h1" ) . text ( ) ;
4
- var titleHeight = $ ( "h1" ) . height ( ) ;
5
5
6
6
// Title animation
7
- $ ( " h1 span" ) . snabbt ( {
8
- fromRotation : [ 0 , 0 , - 8 * Math . PI ] ,
7
+ $ ( ' h1 span' ) . snabbt ( {
8
+ fromRotation : [ 0 , 0 , - 8 * Math . PI ] ,
9
9
delay : function ( i ) {
10
10
return 1000 + i * 100 ;
11
11
} ,
12
12
duration : 1000 ,
13
13
easing : 'ease' ,
14
14
complete : function ( i , length ) {
15
- if ( i === length - 1 ) {
16
- $ ( "h1" ) . snabbt ( {
15
+ if ( i === length - 1 ) {
16
+ $ ( 'h1' ) . snabbt ( {
17
17
transformOrigin : [ 0 , 100 , 0 ] ,
18
- rotation : [ - Math . PI / 4 , 0 , 0 ] ,
18
+ rotation : [ - Math . PI / 4 , 0 , 0 ] ,
19
19
perspective : 300 ,
20
20
easing : 'linear' ,
21
21
delay : 400 ,
@@ -27,39 +27,39 @@ $(function() {
27
27
perspective : 300 ,
28
28
springConstant : 0.2 ,
29
29
springDeceleration : 0.90 ,
30
- springMass : 4 ,
30
+ springMass : 4
31
31
} ) ;
32
32
}
33
33
}
34
34
} ) ;
35
35
36
36
// Title easter egg
37
- $ ( "h1" ) . on ( 'click' , function ( ) {
38
- var width = $ ( "h1" ) . width ( ) ;
39
- $ ( "h1" ) . snabbt ( {
37
+ $ ( 'h1' ) . on ( 'click' , function ( ) {
38
+ var width = $ ( 'h1' ) . width ( ) ;
39
+ $ ( 'h1' ) . snabbt ( {
40
40
fromPosition : [ 0 , 0 , 0 ] ,
41
41
skew : [ 0 , 0.9 ] ,
42
- easing : 'ease' ,
42
+ easing : 'ease'
43
43
} ) . snabbt ( {
44
- position : [ 2 * width , 0 , 0 ] ,
44
+ position : [ 2 * width , 0 , 0 ] ,
45
45
skew : [ 0 , 0 ] ,
46
46
easing : 'easeIn' ,
47
- duration : 200 ,
47
+ duration : 200
48
48
} ) . snabbt ( {
49
- transformOrigin : [ - width / 2 , 0 , 0 ] ,
49
+ transformOrigin : [ - width / 2 , 0 , 0 ] ,
50
50
rotation : [ 0 , - Math . PI , 0 ] ,
51
- fromPosition : [ 2 * width , 0 , 0 ] ,
52
- position : [ 2 * width , 0 , 0 ] ,
51
+ fromPosition : [ 2 * width , 0 , 0 ] ,
52
+ position : [ 2 * width , 0 , 0 ] ,
53
53
perspective : 500 ,
54
54
easing : 'ease' ,
55
- delay : 200 ,
55
+ delay : 200
56
56
} ) . snabbt ( {
57
- transformOrigin : [ width / 2 , 0 , 0 ] ,
57
+ transformOrigin : [ width / 2 , 0 , 0 ] ,
58
58
rotation : [ 0 , 0 , 0 ] ,
59
59
fromPosition : [ 0 , 0 , 0 ] ,
60
60
position : [ 0 , 0 , 0 ] ,
61
61
perspective : 500 ,
62
- easing : 'ease' ,
62
+ easing : 'ease'
63
63
} ) ;
64
64
} ) ;
65
65
@@ -79,56 +79,57 @@ $(function() {
79
79
easing : 'ease'
80
80
} ) . snabbt ( {
81
81
position : [ 0 , 0 , 0 ] ,
82
- fromRotation : [ 0 , 0 , - 2 * Math . PI ] ,
82
+ fromRotation : [ 0 , 0 , - 2 * Math . PI ] ,
83
83
rotation : [ 0 , 0 , 0 ] ,
84
84
easing : 'spring' ,
85
85
springConstant : 0.2 ,
86
86
springDeceleration : 0.90 ,
87
- springMass : 10 ,
87
+ springMass : 10
88
88
} ) ;
89
89
} ;
90
90
91
91
// Easings
92
92
var easingDemos = document . querySelectorAll ( '.easing-demo' ) ;
93
- for ( var i = 0 ; i < easingDemos . length ; ++ i ) {
94
- var container = easingDemos [ i ] ;
93
+ var container ;
94
+ for ( var i = 0 ; i < easingDemos . length ; ++ i ) {
95
+ container = easingDemos [ i ] ;
95
96
var easingName = container . attributes [ 'data-easing-name' ] ;
96
97
var element = container . children [ 0 ] ;
97
- container . onclick = function ( container , element , easingName ) {
98
- var containerWidth = container . offsetWidth ;
99
- var elementWidth = element . offsetWidth ;
100
- snabbt ( element , {
98
+ container . addEventListener ( 'click' , function ( _container , _element , _easingName ) {
99
+ var containerWidth = _container . offsetWidth ;
100
+ var elementWidth = _element . offsetWidth ;
101
+ snabbt ( _element , {
101
102
fromPosition : [ 0 , 0 , 0 ] ,
102
103
position : [ containerWidth - elementWidth , 0 , 0 ] ,
103
- easing : easingName . value ,
104
+ easing : _easingName . value ,
104
105
duration : 500
105
106
} ) ;
106
- } . bind ( undefined , container , element , easingName ) ;
107
+ } . bind ( null , container , element , easingName ) ) ;
107
108
}
108
109
109
110
// Spring easings
110
- $ ( " #spring-example" ) . on ( 'click' , function ( ) {
111
- $ ( " #spring-example" ) . snabbt ( {
111
+ $ ( ' #spring-example' ) . on ( 'click' , function ( ) {
112
+ $ ( ' #spring-example' ) . snabbt ( {
112
113
position : [ 100 , 0 , 0 ] ,
113
114
fromRotation : [ 0 , 0 , 0 ] ,
114
- rotation : [ 0 , 0 , 2 * Math . PI ] ,
115
+ rotation : [ 0 , 0 , 2 * Math . PI ] ,
115
116
easing : 'spring' ,
116
117
springConstant : 0.3 ,
117
- springDeceleration : 0.8 ,
118
+ springDeceleration : 0.8
118
119
} ) . snabbt ( {
119
120
position : [ 0 , 0 , 0 ] ,
120
121
easing : 'spring' ,
121
122
springConstant : 0.3 ,
122
- springDeceleration : 0.8 ,
123
+ springDeceleration : 0.8
123
124
} ) ;
124
125
} ) ;
125
126
126
127
// Custom easing
127
- $ ( " #custom-easer" ) . on ( 'click' , function ( ) {
128
- $ ( " #custom-easer" ) . snabbt ( {
128
+ $ ( ' #custom-easer' ) . on ( 'click' , function ( ) {
129
+ $ ( ' #custom-easer' ) . snabbt ( {
129
130
position : [ 200 , 0 , 0 ] ,
130
131
easing : function ( value ) {
131
- return value + 0.3 * Math . sin ( 2 * Math . PI * value ) ;
132
+ return value + 0.3 * Math . sin ( 2 * Math . PI * value ) ;
132
133
}
133
134
} ) . snabbt ( {
134
135
position : [ 0 , 0 , 0 ] ,
@@ -137,91 +138,89 @@ $(function() {
137
138
} ) ;
138
139
139
140
// Value feed example
140
- $ ( " #value-feed-example" ) . on ( 'click' , function ( ) {
141
- $ ( " #value-feed-example" ) . snabbt ( {
142
- valueFeeder : function ( i , matrix ) {
143
- var x = Math . sin ( i * Math . PI ) ;
144
- return matrix . rotateZ ( Math . sin ( 6 * i * Math . PI ) ) . translate ( x * 200 , 0 , 0 ) ;
141
+ $ ( ' #value-feed-example' ) . on ( 'click' , function ( ) {
142
+ $ ( ' #value-feed-example' ) . snabbt ( {
143
+ valueFeeder : function ( value , matrix ) {
144
+ var x = Math . sin ( value * Math . PI ) ;
145
+ return matrix . rotateZ ( Math . sin ( 6 * value * Math . PI ) ) . translate ( x * 200 , 0 , 0 ) ;
145
146
} ,
146
- duration : 1000 ,
147
+ duration : 1000
147
148
} ) ;
148
149
} ) ;
149
150
150
151
// Transform origin example
151
- $ ( " #transform-origin-example" ) . on ( 'click' , function ( ) {
152
- var elementWidth = $ ( " #transform-origin-example" ) . outerWidth ( ) ;
153
- $ ( " #transform-origin-example" ) . snabbt ( {
152
+ $ ( ' #transform-origin-example' ) . on ( 'click' , function ( ) {
153
+ var elementWidth = $ ( ' #transform-origin-example' ) . outerWidth ( ) ;
154
+ $ ( ' #transform-origin-example' ) . snabbt ( {
154
155
fromRotation : [ 0 , 0 , 0 ] ,
155
- rotation : [ 0 , 2 * Math . PI , 0 ] ,
156
- transformOrigin : [ elementWidth / 2 , 0 , 0 ] ,
157
- perspective : 400 ,
156
+ rotation : [ 0 , 2 * Math . PI , 0 ] ,
157
+ transformOrigin : [ elementWidth / 2 , 0 , 0 ] ,
158
+ perspective : 400
158
159
} ) ;
159
160
} ) ;
160
161
161
162
// Transform origin example
162
- $ ( " #transform-origin-example-2" ) . on ( 'click' , function ( ) {
163
- var elementWidth = $ ( " #transform-origin-example-2" ) . outerWidth ( ) ;
164
- $ ( " #transform-origin-example-2" ) . snabbt ( {
163
+ $ ( ' #transform-origin-example-2' ) . on ( 'click' , function ( ) {
164
+ var elementWidth = $ ( ' #transform-origin-example-2' ) . outerWidth ( ) ;
165
+ $ ( ' #transform-origin-example-2' ) . snabbt ( {
165
166
rotation : [ 0 , Math . PI , 0 ] ,
166
- transformOrigin : [ elementWidth / 2 , 0 , 0 ] ,
167
+ transformOrigin : [ elementWidth / 2 , 0 , 0 ] ,
167
168
perspective : 400 ,
168
169
duration : 300 ,
169
170
easing : 'ease'
170
171
} ) . snabbt ( {
171
- fromPosition : [ 2 * elementWidth , 0 , 0 ] ,
172
- position : [ 2 * elementWidth , 0 , 0 ] ,
172
+ fromPosition : [ 2 * elementWidth , 0 , 0 ] ,
173
+ position : [ 2 * elementWidth , 0 , 0 ] ,
173
174
fromRotation : [ 0 , - Math . PI , 0 ] ,
174
175
rotation : [ 0 , 0 , 0 ] ,
175
- transformOrigin : [ - elementWidth / 2 , 0 , 0 ] ,
176
+ transformOrigin : [ - elementWidth / 2 , 0 , 0 ] ,
176
177
perspective : 400 ,
177
178
duration : 300 ,
178
179
easing : 'ease'
179
180
} ) . snabbt ( {
180
181
fromRotation : [ 0 , 0 , 0 ] ,
181
- fromPosition : [ 2 * elementWidth , 0 , 0 ] ,
182
+ fromPosition : [ 2 * elementWidth , 0 , 0 ] ,
182
183
position : [ 0 , 0 , 0 ] ,
183
184
duration : 300 ,
184
185
easing : 'ease'
185
186
} ) ;
186
187
} ) ;
187
188
188
-
189
-
190
189
// Attention example
191
- $ ( " #attention-example-1" ) . on ( 'click' , function ( ) {
192
- $ ( " #attention-example-1" ) . snabbt ( " attention" , {
193
- rotation : [ 0 , 0 , Math . PI / 2 ] ,
190
+ $ ( ' #attention-example-1' ) . on ( 'click' , function ( ) {
191
+ $ ( ' #attention-example-1' ) . snabbt ( ' attention' , {
192
+ rotation : [ 0 , 0 , Math . PI / 2 ] ,
194
193
springConstant : 1.9 ,
195
- springDeceleration : 0.9 ,
194
+ springDeceleration : 0.9
196
195
} ) ;
197
196
} ) ;
198
197
199
198
// Attention example
200
- $ ( " #attention-example-2" ) . on ( 'click' , function ( ) {
201
- $ ( " #attention-example-2" ) . snabbt ( " attention" , {
199
+ $ ( ' #attention-example-2' ) . on ( 'click' , function ( ) {
200
+ $ ( ' #attention-example-2' ) . snabbt ( ' attention' , {
202
201
position : [ 50 , 0 , 0 ] ,
203
202
springConstant : 2.4 ,
204
- springDeceleration : 0.9 ,
203
+ springDeceleration : 0.9
205
204
} ) ;
206
205
} ) ;
207
206
208
207
// Multi element animation
209
- $ ( " #multi-element-example" ) . on ( 'click' , function ( ) {
210
- $ ( " .multi-example" ) . snabbt ( {
208
+ $ ( ' #multi-element-example' ) . on ( 'click' , function ( ) {
209
+ $ ( ' .multi-example' ) . snabbt ( {
211
210
fromRotation : [ 0 , 0 , 0 ] ,
212
- rotation : function ( i , total ) {
213
- return [ 0 , 0 , ( i / ( total - 1 ) ) * ( Math . PI / 2 ) ] ;
211
+ rotation : function ( value , total ) {
212
+ return [ 0 , 0 , value / ( total - 1 ) * ( Math . PI / 2 ) ] ;
214
213
} ,
215
- delay : function ( i ) {
216
- return i * 50 ;
214
+ delay : function ( index ) {
215
+ return index * 50 ;
217
216
} ,
218
- easing : 'spring' ,
217
+ easing : 'spring'
219
218
} ) . snabbt ( {
220
219
rotation : [ 0 , 0 , 0 ] ,
221
- delay : function ( i , total ) {
222
- return ( total - i - 1 ) * 50 ;
220
+ delay : function ( index , total ) {
221
+ return ( total - index - 1 ) * 50 ;
223
222
} ,
224
- easing : 'ease' ,
223
+ easing : 'ease'
225
224
} ) ;
226
225
} ) ;
227
226
@@ -247,7 +246,7 @@ $(function() {
247
246
animations . push ( snabbt ( flipperBackground , {
248
247
fromScale : [ 0.0 , 0.0 ] ,
249
248
scale : [ 1.0 , 1.0 ] ,
250
- fromRotation : [ 0 , 0 , 2 * Math . PI ] ,
249
+ fromRotation : [ 0 , 0 , 2 * Math . PI ] ,
251
250
rotation : [ 0 , 0 , 0 ] ,
252
251
manual : true ,
253
252
easing : 'ease' ,
@@ -269,7 +268,7 @@ $(function() {
269
268
animations . push ( snabbt ( flipperBackground , {
270
269
scale : [ 0.0 , 0.0 ] ,
271
270
fromRotation : [ 0 , 0 , 0 ] ,
272
- rotation : [ 0 , 0 , 2 * Math . PI ] ,
271
+ rotation : [ 0 , 0 , 2 * Math . PI ] ,
273
272
manual : true ,
274
273
easing : 'ease' ,
275
274
duration : 1000
@@ -282,7 +281,7 @@ $(function() {
282
281
var n = number ;
283
282
return function ( ) {
284
283
n -- ;
285
- if ( n === 0 ) {
284
+ if ( n === 0 ) {
286
285
callback ( ) ;
287
286
}
288
287
} ;
@@ -293,26 +292,26 @@ $(function() {
293
292
var opened = - 1 ;
294
293
var animations = [ ] ;
295
294
hammer . on ( 'pan' , function ( event ) {
296
- if ( ! dragInProgress ) {
297
- if ( opened === - 1 ) {
295
+ if ( ! dragInProgress ) {
296
+ if ( opened === - 1 ) {
298
297
animations = dragRightAnimations ( ) ;
299
298
} else {
300
299
animations = dragLeftAnimations ( ) ;
301
300
}
302
301
dragInProgress = true ;
303
302
}
304
303
305
- var delta = Math . min ( 1 , Math . max ( 0 , ( - opened * event . deltaX ) / 200 ) ) ;
306
- if ( animations . length ) {
304
+ var delta = Math . min ( 1 , Math . max ( 0 , - opened * event . deltaX / 200 ) ) ;
305
+ if ( animations . length ) {
307
306
animations . forEach ( function ( animation ) {
308
307
animation . setValue ( delta ) ;
309
308
} ) ;
310
309
}
311
310
312
311
313
- if ( event . isFinal ) {
314
- if ( animations ) {
315
- if ( delta > 0.5 ) {
312
+ if ( event . isFinal ) {
313
+ if ( animations ) {
314
+ if ( delta > 0.5 ) {
316
315
var finishCallback = debouncedCallback ( function ( ) {
317
316
dragInProgress = false ;
318
317
opened *= - 1 ;
@@ -337,19 +336,19 @@ $(function() {
337
336
} ) ( ) ;
338
337
339
338
// Scroll spy
340
- var navtop = $ ( " #navbar" ) . offset ( ) . top ;
341
- var $dockedNavbar = $ ( " #docked-navbar" ) ;
339
+ var navtop = $ ( ' #navbar' ) . offset ( ) . top ;
340
+ var $dockedNavbar = $ ( ' #docked-navbar' ) ;
342
341
var $window = $ ( window ) ;
343
- $ ( window ) . on ( 'scroll' , function ( event ) {
344
- if ( $window . scrollTop ( ) > navtop ) {
345
- if ( $dockedNavbar . hasClass ( 'hidden' ) )
346
- $ ( " #docked-navbar" ) . removeClass ( " hidden" ) ;
342
+ $ ( window ) . on ( 'scroll' , function ( ) {
343
+ if ( $window . scrollTop ( ) > navtop ) {
344
+ if ( $dockedNavbar . hasClass ( 'hidden' ) )
345
+ $ ( ' #docked-navbar' ) . removeClass ( ' hidden' ) ;
347
346
} else {
348
- if ( ! $dockedNavbar . hasClass ( 'hidden' ) )
349
- $ ( " #docked-navbar" ) . addClass ( " hidden" ) ;
347
+ if ( ! $dockedNavbar . hasClass ( 'hidden' ) )
348
+ $ ( ' #docked-navbar' ) . addClass ( ' hidden' ) ;
350
349
}
351
350
} ) ;
352
351
353
352
FastClick . attach ( document . body ) ;
354
353
355
- } ( ) ) ;
354
+ } ) ( ) ;
0 commit comments