@@ -5,86 +5,101 @@ const group = new Group()
55
66animate ( )
77
8+ const tweenMap = new Map ( )
9+
810const target1 = document . getElementById ( 'target1' )
9- const tween1 = new Tween ( target1 . dataset , group )
10- . to ( { rotation : 360 , y : 300 } , 750 )
11- . repeat ( 1 )
12- . delay ( 1000 )
13- . yoyo ( true )
14- . easing ( Easing . Cubic . InOut )
15- . onUpdate ( function ( object ) {
16- updateBox ( target1 , object )
17- } )
18- . start ( )
11+ tweenMap . set (
12+ 'tween1' ,
13+ new Tween ( target1 . dataset , group )
14+ . to ( { rotation : 360 , y : 300 } , 750 )
15+ . repeat ( Infinity )
16+ . delay ( 1000 )
17+ . yoyo ( true )
18+ . easing ( Easing . Quadratic . InOut )
19+ . onUpdate ( function ( object ) {
20+ updateBox ( target1 , object )
21+ } )
22+ . start ( ) ,
23+ )
1924const target2 = document . getElementById ( 'target2' )
20- const tween2 = new Tween ( target2 . dataset , group )
21- . to ( { rotation : 360 , y : 300 } , 750 )
22- . repeat ( Infinity )
23- . delay ( 1000 )
24- . yoyo ( true )
25- . easing ( Easing . Cubic . InOut )
26- . onUpdate ( function ( object ) {
27- updateBox ( target2 , object )
28- } )
29- . start ( )
25+
26+ tweenMap . set (
27+ 'tween2' ,
28+ new Tween ( target2 . dataset , group )
29+ . to ( { rotation : 360 , y : 300 } , 750 )
30+ . repeat ( Infinity )
31+ . delay ( 1000 )
32+ . yoyo ( true )
33+ . easing ( Easing . Cubic . InOut )
34+ . onUpdate ( function ( object ) {
35+ updateBox ( target2 , object )
36+ } )
37+ . start ( ) ,
38+ )
3039const target3 = document . getElementById ( 'target3' )
31- const tween3 = new Tween ( target3 . dataset , group )
32- . to ( { rotation : '+360' , y : '+300' } , 750 )
33- . repeat ( 1 )
34- . delay ( 1000 )
35- . yoyo ( true )
36- . easing ( Easing . Cubic . InOut )
37- . onUpdate ( function ( object ) {
38- updateBox ( target3 , object )
39- } )
40- . start ( )
40+ tweenMap . set (
41+ 'tween3' ,
42+ new Tween ( target3 . dataset , group )
43+ . to ( { rotation : '+360' , y : '+300' } , 750 )
44+ . repeat ( 1 )
45+ . delay ( 1000 )
46+ . yoyo ( true )
47+ . easing ( Easing . Cubic . InOut )
48+ . onUpdate ( function ( object ) {
49+ updateBox ( target3 , object )
50+ } )
51+ . start ( ) ,
52+ )
4153const target4 = document . getElementById ( 'target4' )
42- const tween4 = new Tween ( target4 . dataset , group )
43- . to ( { rotation : '+360' , y : '+300' } , 750 )
44- . repeat ( Infinity )
45- . delay ( 1000 )
46- . yoyo ( true )
47- . easing ( Easing . Cubic . InOut )
48- . onUpdate ( function ( object ) {
49- updateBox ( target4 , object )
50- } )
51- . start ( )
54+ tweenMap . set (
55+ 'tween4' ,
56+ new Tween ( target4 . dataset , group )
57+ . to ( { rotation : '+360' , y : '+300' } , 750 )
58+ . repeat ( Infinity )
59+ . delay ( 1000 )
60+ . yoyo ( true )
61+ . easing ( Easing . Quadratic . InOut )
62+ . onUpdate ( function ( object ) {
63+ updateBox ( target4 , object )
64+ } )
65+ . start ( ) ,
66+ )
67+
68+ const target5 = document . getElementById ( 'target5' )
69+ tweenMap . set (
70+ 'tween5' ,
71+ new Tween ( target5 . dataset , group )
72+ . to ( { rotation : '+360' , y : '+300' } , 1050 )
73+ . repeat ( Infinity )
74+ // .delay(1000) // without delay
75+ . yoyo ( true )
76+ . easing ( Easing . Quadratic . InOut )
77+ . onUpdate ( function ( object ) {
78+ updateBox ( target5 , object )
79+ } )
80+ . start ( ) ,
81+ )
5282
5383// TODO perhaps add these methods to Group
5484
5585const restart = ( window . restart = function ( ) {
56- tween1 . stop ( ) . start ( )
57- tween2 . stop ( ) . start ( )
58- tween3 . stop ( ) . start ( )
59- tween4 . stop ( ) . start ( )
86+ tweenMap . forEach ( tween => tween . start ( ) )
6087} )
6188
6289const stop = ( window . stop = function ( ) {
63- tween1 . stop ( )
64- tween2 . stop ( )
65- tween3 . stop ( )
66- tween4 . stop ( )
90+ tweenMap . forEach ( tween => tween . stop ( ) )
6791} )
6892
6993const start = ( window . start = function ( ) {
70- tween1 . start ( )
71- tween2 . start ( )
72- tween3 . start ( )
73- tween4 . start ( )
94+ tweenMap . forEach ( tween => tween . start ( ) )
7495} )
7596
7697const pause = ( window . pause = function ( ) {
77- tween1 . pause ( )
78- tween2 . pause ( )
79- tween3 . pause ( )
80- tween4 . pause ( )
98+ tweenMap . forEach ( tween => tween . pause ( ) )
8199} )
82100
83101const resume = ( window . resume = function ( ) {
84- tween1 . resume ( )
85- tween2 . resume ( )
86- tween3 . resume ( )
87- tween4 . resume ( )
102+ tweenMap . forEach ( tween => tween . resume ( ) )
88103} )
89104
90105function animate ( time ) {
0 commit comments