From d512d8d0827f07b969e439dab9e2293a376a26bc Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 5 Feb 2014 02:12:12 +0400 Subject: [PATCH] more testing... Signed-off-by: Alex A. Naanou --- lib/jli.js | 82 ++++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/lib/jli.js b/lib/jli.js index 3ff9301..a4f556d 100755 --- a/lib/jli.js +++ b/lib/jli.js @@ -475,34 +475,18 @@ function animateElementTo2(elem, to, duration, easing, speed, use_transitions){ var start = Date.now() var then = start + duration var from = getElementShift(elem) - var cur = { - top: from.top, - left: from.left - } - var dist = { - top: to.top - from.top, - 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' - if(Math.abs(dist[direction]) >= 1){ - d = ((t - start) * speed[v]) - if(Math.abs(dist[direction]) > Math.abs(d)){ - dist[direction] -= d - cur[direction] = Math.round(cur[direction] + d) - // normalize... - cur[direction] = Math.abs(dist[direction]) <= 1 ? to[direction] : cur[direction] - // calc speed for next step... - speed[v] = dist[direction] / (duration - (t - start)) - } else { - cur[direction] = to[direction] - } - } - } - */ + // do var caching... + var to_top = to.top + var to_left = to.left + var speen_x = speed.x + var speen_y = speed.y + var from_top = from.top + var from_left = from.left + var cur_top = from_top + var cur_left = form_left + var dist_top = to_top - from_top + var dist_left = to_left - from_left var runner = animationFrameRunner(function(){ var t = Date.now() @@ -517,44 +501,46 @@ 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) - 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) + // NOTE: these are inlined here for speed... + 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 + cur_top = Math.abs(dist_top) <= 1 ? to_top : cur_top // calc speed for next step... - speed.y = dist.top / (duration - (t - start)) + speed_y = dist_top / (duration - (t - start)) } else { - cur.top = to.top + 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) + 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 + cur_left = Math.abs(dist_left) <= 1 ? to_left : cur_left // calc speed for next step... - speed.x = dist.left / (duration - (t - start)) + speed_x = dist_left / (duration - (t - start)) } else { - cur.left = to.left + cur_left = to_left } } // liner speed... } else { var r = (t - start) / duration - cur.top = Math.round(from.top + (dist.top * r)) - cur.left = Math.round(from.left + (dist.left * r)) + cur_top = Math.round(from_top + (dist_top * r)) + cur_left = Math.round(from_left + (dist_left * r)) } // do the actual move... - setElementTransform(elem, cur) + setElementTransform(elem, { + top: cur_top, + left: cur_left + }) }) elem.data('animating', runner)