Created
March 9, 2020 22:52
-
-
Save nullx5/b6350452019c850b961e2ff5798e5b4d to your computer and use it in GitHub Desktop.
Challenge Catwalk | khanacademy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Challenge: Catwalk</title> | |
<style> | |
#cat { | |
position: absolute; | |
left: 0px; | |
} | |
</style> | |
</head> | |
<body> | |
<div> | |
<!-- Cat walking GIF from: http://www.anniemation.com/clip_art/graphics.html --> | |
<img id="cat" src="https://www.kasandbox.org/programming-images/misc/cat-walk.gif"> | |
</div> | |
<script> | |
var catEl = document.getElementById("cat"); | |
var startTime = new Date().getTime(); | |
var walkTheCat = function () { | |
var currTime = new Date().getTime(); | |
var secondsElapsed = ((currTime - startTime) / 1000); | |
var newLeft = 30 * secondsElapsed; | |
catEl.style.left = newLeft + "px"; | |
window.requestAnimationFrame(walkTheCat); | |
}; | |
walkTheCat(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment