diff --git a/lib/jli.js b/lib/jli.js index ac80995..3ff9301 100755 --- a/lib/jli.js +++ b/lib/jli.js @@ -484,6 +484,7 @@ function animateElementTo2(elem, to, duration, easing, speed, use_transitions){ left: to.left - from.left, } + /* // accepts either 'top' or 'left' the rest is passed as closures... var _shift = function(direction, t){ var v = direction == 'top' ? 'y' : 'x' @@ -501,6 +502,7 @@ function animateElementTo2(elem, to, duration, easing, speed, use_transitions){ } } } + */ var runner = animationFrameRunner(function(){ var t = Date.now() @@ -515,8 +517,34 @@ function animateElementTo2(elem, to, duration, easing, speed, use_transitions){ // calculate target position for current step... // XXX do propper easing... if(speed != null){ - _shift('top', t) - _shift('left', t) + //_shift('top', t) + //_shift('left', t) + if(Math.abs(dist.top) >= 1){ + dy = ((t - start) * speed.y) + if(Math.abs(dist.top) > Math.abs(dy)){ + dist.top -= dy + cur.top = Math.round(cur.top + dy) + // normalize... + cur.top = Math.abs(dist.top) <= 1 ? to.top : cur.top + // calc speed for next step... + speed.y = dist.top / (duration - (t - start)) + } else { + cur.top = to.top + } + } + if(Math.abs(dist.left) >= 1){ + dx = ((t - start) * speed.x) + if(Math.abs(dist.left) > Math.abs(dx)){ + dist.left -= dx + cur.left = Math.round(cur.left + dx) + // normalize... + cur.left = Math.abs(dist.left) <= 1 ? to.left : cur.left + // calc speed for next step... + speed.x = dist.left / (duration - (t - start)) + } else { + cur.left = to.left + } + } // liner speed... } else {