serebann,
может так вам проще будет
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<style>
#brick {
width: 10px;
height: 20px;
background: #EE6B47;
position: relative;
cursor: pointer;
}
#path {
outline: 1px solid #E8C48E;
width: 810px;
height: 20px;
}
</style>
<script>
function animate(options) {
var start = performance.now();
requestAnimationFrame(function animate(time) {
// timeFraction от 0 до 1
var timeFraction = (time - start) / options.duration;
if (timeFraction > 1) timeFraction = 1;
// текущее состояние анимации
var progress = options.timing(timeFraction)
options.draw(progress);
if (timeFraction < 1) {
requestAnimationFrame(animate);
}
if (timeFraction == 1) {
options.callback && options.callback();
}
});
}
</script>
</head>
<body>
<div id="path">
<div id="brick"></div>
</div>
<script>
var sum = 400;
function makeEaseOut(timing) {
return function(timeFraction) {
return 1 - timing(1 - timeFraction);
}
}
function bounce(timeFraction) {
for (var a = 0, b = 1, result; 1; a += b, b /= 2) {
if (timeFraction >= (7 - 4 * a) / 11) {
return -Math.pow((11 - 6 * a - 11 * timeFraction) / 4, 2) + Math.pow(b, 2)
}
}
}
var bounceEaseOut = makeEaseOut(bounce);
(function go() {
animate({
duration: 5000,
timing: bounceEaseOut,
draw: function(progress) {
brick.style.left = progress * sum + 'px';
},
callback : function() {
sum =(810+1) * Math.random() | 0;
window.setTimeout(go,10000)
}
});
}());
</script>
</body>
</html>