Skip to content

Instantly share code, notes, and snippets.

@StoneCypher
Created March 14, 2016 21:45
Show Gist options
  • Save StoneCypher/1f30dbe11bb836e9c6db to your computer and use it in GitHub Desktop.
Save StoneCypher/1f30dbe11bb836e9c6db to your computer and use it in GitHub Desktop.
animating a box allows you to see the problem visually, so that you can confirm it without a debugger
<!doctype html>
<html>
<head>
<style type="text/css">
#box { height: 100px; width: 100px; border: 1px solid blue; background-color: lightblue; }
</style>
<script type="text/javascript">
var i=0;
var frame = function() {
document.getElementById('label').innerHTML = (i++).toString();
document.getElementById('box').style.marginLeft = ((i % 400).toString() + 'px');
window.requestAnimationFrame(frame);
};
window.requestAnimationFrame(frame);
</script>
</head>
<body>
<div id="label"></div>
<div id="box"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment