Created
December 18, 2017 12:59
-
-
Save herbowicz/2b5f6a018f15f0f5e5b2963c6ac1b2db to your computer and use it in GitHub Desktop.
Fidget spinner in CSS
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
<div id='app'> | |
<div class='push-button' data-js-spin></div> | |
</div> |
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
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 }) | |
}) | |
} |
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 { | |
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