Created
March 21, 2016 21:02
-
-
Save paulrouget/99442585974f6661b7c5 to your computer and use it in GitHub Desktop.
This file contains 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
<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