@@ -123,7 +123,7 @@ var chemicalElements = [
123
123
] ;
124
124
125
125
var domElements = [ ] ;
126
- var springConstant = 0.5 ;
126
+ var springConstant = 0.4 ;
127
127
var springDeceleration = 0.7 ;
128
128
129
129
function elementDelay ( i ) {
@@ -154,22 +154,20 @@ function createElements() {
154
154
155
155
function tableFormation ( ) {
156
156
var columns = 17 ;
157
- var rows = 9 ;
157
+ var rows = 10 ;
158
158
var spacing = 60 ;
159
159
var baseXOffset = - Math . floor ( columns / 2 ) * spacing ;
160
160
var baseYOffset = - Math . floor ( rows / 2 ) * spacing ;
161
161
snabbt ( domElements , {
162
162
rotation : [ 0 , 0 , 0 ] ,
163
163
position : function ( i ) {
164
164
var e = chemicalElements [ i ] ;
165
- //return [spacing - (i % 2) * 2 * spacing, e.period * spacing, 0];
166
165
return [ baseXOffset + ( e . group - 1 ) * spacing , baseYOffset + e . period * spacing , 0 ] ;
167
166
} ,
168
167
easing : 'spring' ,
169
168
springConstant : springConstant ,
170
169
springDeceleration : springDeceleration ,
171
170
delay : elementDelay
172
-
173
171
} ) ;
174
172
}
175
173
@@ -190,8 +188,6 @@ function gridFormation() {
190
188
var col = indexWithinLayer % cols ;
191
189
return [ baseXOffset + col * spacing , baseYOffset + row * spacing , layerOffset - layerIndex * layerSpacing ] ;
192
190
} ,
193
- //delay: function(i) { return i * 5; },
194
- duration : 10000 ,
195
191
easing : 'spring' ,
196
192
springConstant : springConstant ,
197
193
springDeceleration : springDeceleration ,
@@ -225,7 +221,6 @@ function spiralFormation() {
225
221
}
226
222
227
223
function setupCameraControls ( container , root ) {
228
- var hammertime = new Hammer ( container , { direction : Hammer . DIRECTION_ALL } ) ;
229
224
var translateZ = 0 ;
230
225
var rotateX = 0 ;
231
226
var rotateY = 0 ;
@@ -235,8 +230,10 @@ function setupCameraControls(container, root) {
235
230
var rotateYVelocity = 0 ;
236
231
237
232
root . style . transform = 'perspective(1000px) rotateY(0deg) rotateX(0deg)' ;
233
+ root . style . webkitTransform = 'perspective(1000px) rotateY(0deg) rotateX(0deg)' ;
238
234
function updateCamera ( rotX , rotY , transZ ) {
239
- root . style . transform = 'perspective(1000px) translateZ(' + transZ + 'px) rotateY(' + rotX + 'deg) rotateX(' + rotY + 'deg)' ;
235
+ root . style . transform = 'perspective(1000px) translateZ(' + transZ + 'px) rotateY(' + rotX + 'deg) rotateX(' + - rotY + 'deg)' ;
236
+ root . style . webkitTransform = 'perspective(1000px) translateZ(' + transZ + 'px) rotateY(' + rotX + 'deg) rotateX(' + - rotY + 'deg)' ;
240
237
}
241
238
242
239
function stepCamera ( ) {
@@ -245,15 +242,20 @@ function setupCameraControls(container, root) {
245
242
var rotX = rotateX + rotateXOffset ;
246
243
var rotY = rotateY + rotateYOffset ;
247
244
248
-
249
245
rotateXVelocity *= 0.99 ;
250
246
rotateYVelocity *= 0.99 ;
247
+
251
248
updateCamera ( rotX , rotY , translateZ ) ;
252
249
253
250
window . requestAnimationFrame ( stepCamera ) ;
254
251
}
255
252
window . requestAnimationFrame ( stepCamera ) ;
256
253
254
+ var hammertime = new Hammer ( container , { direction : Hammer . DIRECTION_ALL } ) ;
255
+ hammertime . get ( 'pan' ) . set ( { direction : Hammer . DIRECTION_ALL } ) ;
256
+ hammertime . get ( 'pinch' ) . set ( { enable : true } ) ;
257
+
258
+
257
259
hammertime . on ( 'pan' , function ( ev ) {
258
260
259
261
rotateXOffset = ev . deltaX / 10 ;
@@ -268,12 +270,17 @@ function setupCameraControls(container, root) {
268
270
rotateXOffset = 0 ;
269
271
rotateYOffset = 0 ;
270
272
}
271
- updateCamera ( ) ;
272
273
} ) ;
273
274
container . addEventListener ( 'mousewheel' , function ( ev ) {
274
275
translateZ += ev . deltaY ;
275
276
translateZ = Math . min ( Math . max ( 0 , translateZ ) , 600 ) ;
276
- updateCamera ( ) ;
277
+ } ) ;
278
+
279
+ var log = document . getElementById ( 'log' ) ;
280
+ hammertime . on ( 'pinch' , function ( ev ) {
281
+ //ev.scale
282
+ log . innerText = ev . scale ;
283
+ translateZ = Math . min ( ( ev . scale - 1 ) * 600 , 600 ) ;
277
284
} ) ;
278
285
}
279
286
@@ -284,27 +291,55 @@ function initEventListeners() {
284
291
var gridButton = document . getElementById ( 'grid' ) ;
285
292
var spiralButton = document . getElementById ( 'spiral' ) ;
286
293
287
- window . addEventListener ( 'scroll' , function ( evt ) {
288
- console . log ( 'scroll' ) ;
289
- evt . preventDefault ( ) ;
290
- evt . stopPropagation ( ) ;
291
- return false ;
292
- } ) ;
293
-
294
294
tableButton . addEventListener ( 'click' , function ( ) {
295
295
tableFormation ( ) ;
296
+ tableButton . classList . add ( 'controls__button--selected' ) ;
297
+ gridButton . classList . remove ( 'controls__button--selected' ) ;
298
+ spiralButton . classList . remove ( 'controls__button--selected' ) ;
296
299
} ) ;
297
300
gridButton . addEventListener ( 'click' , function ( ) {
298
301
gridFormation ( ) ;
302
+ tableButton . classList . remove ( 'controls__button--selected' ) ;
303
+ gridButton . classList . add ( 'controls__button--selected' ) ;
304
+ spiralButton . classList . remove ( 'controls__button--selected' ) ;
299
305
} ) ;
300
306
spiralButton . addEventListener ( 'click' , function ( ) {
301
307
spiralFormation ( ) ;
308
+ tableButton . classList . remove ( 'controls__button--selected' ) ;
309
+ gridButton . classList . remove ( 'controls__button--selected' ) ;
310
+ spiralButton . classList . add ( 'controls__button--selected' ) ;
302
311
} ) ;
303
312
304
313
setupCameraControls ( container , root ) ;
305
314
}
306
315
316
+ function initPositions ( ) {
317
+ var distance = 400 ;
318
+ snabbt ( domElements , {
319
+ fromPosition : function ( ) {
320
+ return [
321
+ distance - 2 * distance * Math . random ( ) ,
322
+ distance - 2 * distance * Math . random ( ) ,
323
+ distance - 2 * distance * Math . random ( )
324
+ ] ;
325
+ } ,
326
+ position : function ( ) {
327
+ return [
328
+ distance - 2 * distance * Math . random ( ) ,
329
+ distance - 2 * distance * Math . random ( ) ,
330
+ distance - 2 * distance * Math . random ( )
331
+ ] ;
332
+ } ,
333
+ fromOpacity : 0 ,
334
+ opacity : 1 ,
335
+ duration : 1000 ,
336
+ easing : 'ease' ,
337
+ allDone : function ( ) {
338
+ tableFormation ( ) ;
339
+ }
340
+ } ) ;
341
+ }
342
+
307
343
createElements ( ) ;
308
- tableFormation ( ) ;
309
- //rootAnimation();
344
+ initPositions ( ) ;
310
345
initEventListeners ( ) ;
0 commit comments