Last active
July 24, 2019 03:50
-
-
Save sea-witch/5a013c966f2abc2043ea9ad51660f698 to your computer and use it in GitHub Desktop.
Demo request animation frame
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
<html> | |
<body> | |
<div id="smiley" style="position: absolute;">😌</div> | |
<script> | |
const {requestAnimationFrame} = window | |
let i = 0 | |
const smiley = document.querySelector('#smiley') | |
function step() { | |
update() | |
requestAnimationFrame(step) | |
} | |
function update() { | |
i = i < 200 ? i + 1 : 0 | |
smiley.style.left = Math.sin(i / 10) * 10 + 50 | |
smiley.style.top = i / 2 | |
} | |
step() | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment