Skip to content

Instantly share code, notes, and snippets.

@herbowicz
Created December 18, 2017 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herbowicz/2b5f6a018f15f0f5e5b2963c6ac1b2db to your computer and use it in GitHub Desktop.
Save herbowicz/2b5f6a018f15f0f5e5b2963c6ac1b2db to your computer and use it in GitHub Desktop.
Fidget spinner in CSS
<div id='app'>
<div class='push-button' data-js-spin></div>
</div>
var $spin = document.querySelector('[data-js-spin]')
$spin.addEventListener('touchmove', () => {
spin($spin, { theta: 0, av: 30 })
})
function spin (el, { theta, av }) {
theta += av
el.style.transform = `rotate(${theta}deg)`
av *= 0.99
if (av < 0.001) return
requestAnimationFrame(() => {
spin(el, { theta, av })
})
}
html, body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
body {
text-align: center;
display: flex;
justify-content: center;
align-items: center;
background-color: black;
}
.push-button {
width: 400px;
height: 400px;
background-image: url('http://goa.cool/s/l.png');
cursor: pointer;
user-select: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment