Skip to content

Instantly share code, notes, and snippets.

@nullx5
Created March 9, 2020 22:52
Show Gist options
  • Save nullx5/b6350452019c850b961e2ff5798e5b4d to your computer and use it in GitHub Desktop.
Save nullx5/b6350452019c850b961e2ff5798e5b4d to your computer and use it in GitHub Desktop.
Challenge Catwalk | khanacademy
<!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