Skip to content

Instantly share code, notes, and snippets.

@rocbear
Last active August 29, 2015 14:20
Show Gist options
  • Save rocbear/8bc6a8e7607411cad20f to your computer and use it in GitHub Desktop.
Save rocbear/8bc6a8e7607411cad20f to your computer and use it in GitHub Desktop.
Sine wave using Date.now()
var d = Math.sin(Date.now() * frequency) * amplitude);
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;
}
<div class="container">
<div class="disc"></div>
</div>
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