Last active
August 29, 2015 14:20
-
-
Save rocbear/8bc6a8e7607411cad20f to your computer and use it in GitHub Desktop.
Sine wave using Date.now()
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
| var d = Math.sin(Date.now() * frequency) * amplitude); |
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: 30px; | |
| } | |
| .container{ | |
| perspective: 500px; | |
| position: absolute; | |
| width: 50px; | |
| height: 50px; | |
| } | |
| .disc{ | |
| background-color: lightblue; | |
| position: relative; | |
| top: 0; | |
| left: 0; | |
| width: 50px; | |
| height: 50px; | |
| border-radius: 25px; | |
| } |
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="disc"></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
| var frequency = 0.005, | |
| amplitude = 50, | |
| elem = document.querySelector('.disc'), | |
| update = function(){ | |
| elem.style.transform = 'translateZ(' + (Math.sin(Date.now() * frequency) * amplitude) + 'px)'; | |
| requestAnimationFrame(update); | |
| }; | |
| update(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment