@@ -19,9 +19,9 @@ <h2>20 _ timeline</h2>
1919 < p > Sequencing with Timeline: sequential by default, parallel via offsets and labels.</ p >
2020 </ div >
2121 < div style ="position: absolute; top: 100px; left: 400px ">
22- < div id ="target1 " data-x ="0 " data-rotation ="0 " class ="box "> sequential</ div >
23- < div id ="target2 " data-x ="0 " data-rotation ="0 " class ="box "> parallel</ div >
24- < div id ="target3 " data-x ="0 " data-rotation ="0 " class ="box "> labels + nesting</ div >
22+ < div id ="target1 " data-y ="0 " data-rotation ="0 " class ="box "> sequential</ div >
23+ < div id ="target2 " data-y ="0 " data-rotation ="0 " class ="box "> parallel</ div >
24+ < div id ="target3 " data-y ="0 " data-rotation ="0 " class ="box "> labels + nesting</ div >
2525 </ div >
2626
2727 < script type ="module ">
@@ -35,43 +35,38 @@ <h2>20 _ timeline</h2>
3535 function init ( ) {
3636 // 1. Sequential: add() appends after the last child (replaces chain).
3737 const target1 = document . getElementById ( 'target1' )
38- const seq = new Timeline ( )
39- . add ( new Tween ( target1 . dataset ) . to ( { x : 200 } , 800 ) . easing ( Easing . Quadratic . InOut ) )
40- . add ( new Tween ( target1 . dataset ) . to ( { x : 0 } , 800 ) . easing ( Easing . Quadratic . InOut ) )
41- . onUpdate ( function ( ) {
42- updateBox ( target1 , target1 . dataset )
43- } )
44- seq . start ( )
45- timelines . push ( seq )
38+ const sequence = new Timeline ( )
39+ . add ( new Tween ( target1 . dataset ) . to ( { y : 200 } , 800 ) . easing ( Easing . Quadratic . InOut ) )
40+ . add ( new Tween ( target1 . dataset ) . to ( { y : 0 } , 800 ) . easing ( Easing . Quadratic . InOut ) )
41+ . onUpdate ( ( ) => updateBox ( target1 , target1 . dataset ) )
42+ sequence . start ( )
43+ timelines . push ( sequence )
4644
4745 // 2. Parallel: explicit offset 0 starts children together
4846 // (two tweens, two different properties of the same box).
4947 const target2 = document . getElementById ( 'target2' )
50- const par = new Timeline ( )
51- . add ( new Tween ( target2 . dataset ) . to ( { x : 200 } , 1000 ) . easing ( Easing . Sinusoidal . InOut ) , 0 )
48+ const parallel = new Timeline ( )
49+ . add ( new Tween ( target2 . dataset ) . to ( { y : 200 } , 1000 ) . easing ( Easing . Sinusoidal . InOut ) , 0 )
5250 . add ( new Tween ( target2 . dataset ) . to ( { rotation : 360 } , 1000 ) . easing ( Easing . Sinusoidal . InOut ) , 0 )
53- . onUpdate ( function ( ) {
54- updateBox ( target2 , target2 . dataset )
55- } )
56- par . start ( )
57- timelines . push ( par )
51+ . add ( new Tween ( target2 . dataset ) . to ( { y : 0 } , 1000 ) . easing ( Easing . Sinusoidal . InOut ) )
52+ . onUpdate ( ( ) => updateBox ( target2 , target2 . dataset ) )
53+ parallel . start ( )
54+ timelines . push ( parallel )
5855
5956 // 3. Labels and nesting: an inner timeline inside an outer one.
6057 // The spin starts 200ms after the 'moved' label, leaving a gap.
6158 const target3 = document . getElementById ( 'target3' )
6259 const inner = new Timeline ( )
63- . add ( new Tween ( target3 . dataset ) . to ( { x : 200 } , 600 ) . easing ( Easing . Quadratic . Out ) , 0 )
60+ . add ( new Tween ( target3 . dataset ) . to ( { y : 200 } , 600 ) . easing ( Easing . Quadratic . Out ) , 0 )
6461 . addLabel ( 'moved' , 600 )
6562 . add ( new Tween ( target3 . dataset ) . to ( { rotation : 180 } , 600 ) . easing ( Easing . Quadratic . InOut ) , {
6663 at : 'moved' ,
6764 offset : 200 ,
6865 } )
6966 . add ( new Tween ( target3 . dataset ) . to ( { rotation : 0 } , 600 ) . easing ( Easing . Quadratic . InOut ) )
70- . add ( new Tween ( target3 . dataset ) . to ( { x : 0 } , 600 ) . easing ( Easing . Quadratic . InOut ) )
67+ . add ( new Tween ( target3 . dataset ) . to ( { y : 0 } , 600 ) . easing ( Easing . Quadratic . InOut ) )
7168
72- const outer = new Timeline ( ) . add ( inner , 0 ) . onUpdate ( function ( ) {
73- updateBox ( target3 , target3 . dataset )
74- } )
69+ const outer = new Timeline ( ) . add ( inner , 0 ) . onUpdate ( ( ) => updateBox ( target3 , target3 . dataset ) )
7570 outer . start ( )
7671 timelines . push ( outer )
7772 }
@@ -86,7 +81,7 @@ <h2>20 _ timeline</h2>
8681
8782 function updateBox ( box , params ) {
8883 const s = box . style ,
89- transform = 'translateX (' + Math . floor ( params . x ) + 'px) rotate(' + Math . floor ( params . rotation ) + 'deg)'
84+ transform = 'translateY (' + Math . floor ( params . y ) + 'px) rotate(' + Math . floor ( params . rotation ) + 'deg)'
9085 s . webkitTransform = transform
9186 s . mozTransform = transform
9287 s . transform = transform
0 commit comments