Skip to content

Instantly share code, notes, and snippets.

@paulfarino
Created June 28, 2017 17:58
Show Gist options
  • Save paulfarino/2b8f12c57ce94836b933ca8f0ffd8270 to your computer and use it in GitHub Desktop.
Save paulfarino/2b8f12c57ce94836b933ca8f0ffd8270 to your computer and use it in GitHub Desktop.
Request Animation Frame example
<div class="container">
<div class="test">Test</div>
</div>
// 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);
});
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