We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 70914a8 commit 53752cfCopy full SHA for 53752cf
DOM_basic/cat_hat.completejavascript.com.js
@@ -0,0 +1,23 @@
1
+<img src="img/cat.png" id="cat" style="position: absolute">
2
+<img src="img/hat.png" id="hat" style="position: absolute">
3
+
4
+<script>
5
+ var cat = document.querySelector("#cat");
6
+ var hat = document.querySelector("#hat");
7
+ var angle = 0, lastTime = null;
8
9
+ function animate(time) {
10
+ if (lastTime != null)
11
+ angle += (time - lastTime) * 0.001;
12
+ lastTime = time;
13
14
+ cat.style.top = (Math.sin(angle) * 20) + "px";
15
+ cat.style.left = (Math.cos(angle) * 200 + 300) + "px";
16
17
+ hat.style.top = (-Math.sin(angle) * 20) + "px";
18
+ hat.style.left = (-Math.cos(angle) * 200 + 300) + "px";
19
20
+ requestAnimationFrame(animate);
21
+ }
22
23
+</script>
0 commit comments