Skip to content

Commit 53752cf

Browse files
Create cat_hat.completejavascript.com.js
1 parent 70914a8 commit 53752cf

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
requestAnimationFrame(animate);
23+
</script>

0 commit comments

Comments
 (0)