Skip to content

Instantly share code, notes, and snippets.

@ivanmalagon
Created September 22, 2016 10:30
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 ivanmalagon/96556c2ae76c5ff97c4bc25148516602 to your computer and use it in GitHub Desktop.
Save ivanmalagon/96556c2ae76c5ff97c4bc25148516602 to your computer and use it in GitHub Desktop.
Easing function proof of concept
<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