Skip to content

Instantly share code, notes, and snippets.

@paulrouget
Created March 21, 2016 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulrouget/99442585974f6661b7c5 to your computer and use it in GitHub Desktop.
Save paulrouget/99442585974f6661b7c5 to your computer and use it in GitHub Desktop.
<div style="width: 200px; height: 10px; background: red"></div>
<script>
var div = document.querySelector("div");
var x = 0;
var sign = 1;
// Comment this line out to test with native rAF
// window.requestAnimationFrame = c => setTimeout(c, 16);
function step() {
x += sign * 1;
if (x == 100 || x == 0) {
sign = -sign;
}
div.style.transform = `translateX(${x}px)`;
requestAnimationFrame(step);
}
step();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment