Created
September 22, 2016 10:30
-
-
Save ivanmalagon/96556c2ae76c5ff97c4bc25148516602 to your computer and use it in GitHub Desktop.
Easing function proof of concept
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> | |
<head> | |
<style> | |
.orange { | |
height: 64; | |
width: 64; | |
margin-top: 64; | |
margin-left: 64; | |
background-color: orange; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="box" class="orange"></div> | |
<script> | |
function easeInOutCubic (t, b, c, d) { | |
t /= d/2; | |
if (t < 1) return c/2*t*t*t + b; | |
t -= 2; | |
return c/2*(t*t*t + 2) + b; | |
}; | |
var start = null; | |
var box = document.getElementById('box'); | |
function paint(timestamp) { | |
if (!start) { | |
start = timestamp | |
} | |
var value = easeInOutCubic(timestamp - start, 64, 512, 2000); | |
box.style.marginLeft = value; | |
if (value < 64 + 512) { | |
requestAnimationFrame(paint); | |
} else { | |
start = null; | |
} | |
} | |
function move() { | |
window.requestAnimationFrame(paint); | |
} | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment