Skip to content

Instantly share code, notes, and snippets.

@sea-witch
Last active July 24, 2019 03:50
Show Gist options
  • Save sea-witch/5a013c966f2abc2043ea9ad51660f698 to your computer and use it in GitHub Desktop.
Save sea-witch/5a013c966f2abc2043ea9ad51660f698 to your computer and use it in GitHub Desktop.
Demo request animation frame
<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