Created
June 28, 2017 17:58
-
-
Save paulfarino/2b8f12c57ce94836b933ca8f0ffd8270 to your computer and use it in GitHub Desktop.
Request Animation Frame example
This file contains hidden or 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 class="container"> | |
<div class="test">Test</div> | |
</div> |
This file contains hidden or 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
// Modified from Benjamin De Cock (twitter.com/bdc) | |
// http://playground.deaxon.com/js/css-waapi-easing/ | |
requestAnimationFrame(() => { | |
const [js] = document.querySelectorAll(".test"); | |
const transform = [ | |
"translate(0)", | |
"translate(calc(50vw - var(--size) / 2))", | |
"translate(calc(100vw - var(--size)))" | |
]; | |
const options = { | |
duration: 5000, | |
easing: "cubic-bezier(.2, 1, .2, 1)", | |
iterations: Infinity | |
}; | |
js.animate({transform}, options); | |
}); |
This file contains hidden or 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
body { | |
margin: 0 | |
} | |
.container { | |
--size: 200px; | |
display: grid; | |
height: 100vh; | |
padding: 0; | |
grid: auto-flow var(--size) / var(--size); | |
grid-gap: 5em; | |
align-content: center; | |
list-style: none; | |
text-align: center; | |
font: 500 13px/var(--size) -apple-system, BlinkMacSystemFont, sans-serif | |
} | |
.test { | |
border-radius: 50%; | |
background: aquamarine; | |
will-change: transform | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment