File tree 1 file changed +24
-0
lines changed
14. Document Object Model
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ < style > body { min-height : 200px }</ style >
2
+ < img src ="img/cat.png " id ="cat " style ="position: absolute ">
3
+ < img src ="img/hat.png " id ="hat " style ="position: absolute ">
4
+
5
+ < script >
6
+ let cat = document . querySelector ( "#cat" ) ;
7
+ let hat = document . querySelector ( "#hat" ) ;
8
+
9
+ let angle = 0 ;
10
+ let lastTime = null ;
11
+ function animate ( time ) {
12
+ if ( lastTime != null ) angle += ( time - lastTime ) * 0.001 ;
13
+ lastTime = time ;
14
+ cat . style . top = ( Math . sin ( angle ) * 40 + 40 ) + "px" ;
15
+ cat . style . left = ( Math . cos ( angle ) * 200 + 230 ) + "px" ;
16
+
17
+ // Your extensions here.
18
+ hat . style . top = ( Math . sin ( angle + Math . PI ) * 40 + 40 ) + "px" ;
19
+ hat . style . left = ( Math . cos ( angle + Math . PI ) * 200 + 230 ) + "px" ;
20
+
21
+ requestAnimationFrame ( animate ) ;
22
+ }
23
+ requestAnimationFrame ( animate ) ;
24
+ </ script >
You can’t perform that action at this time.
0 commit comments