Skip to content

Instantly share code, notes, and snippets.

@bogoreh
Last active March 12, 2021 05:56
Show Gist options
  • Select an option

  • Save bogoreh/2ee88142a557900dd3c92e930046395c to your computer and use it in GitHub Desktop.

Select an option

Save bogoreh/2ee88142a557900dd3c92e930046395c to your computer and use it in GitHub Desktop.
<!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 = secondsElapsed * 67 + 1 + "px";
catEl.style.left = newLeft;
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