more testing...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-02-05 02:12:12 +04:00
parent 1e7eec0ab5
commit d512d8d082

View File

@ -475,34 +475,18 @@ function animateElementTo2(elem, to, duration, easing, speed, use_transitions){
var start = Date.now() var start = Date.now()
var then = start + duration var then = start + duration
var from = getElementShift(elem) var from = getElementShift(elem)
var cur = {
top: from.top,
left: from.left
}
var dist = {
top: to.top - from.top,
left: to.left - from.left,
}
/* // do var caching...
// accepts either 'top' or 'left' the rest is passed as closures... var to_top = to.top
var _shift = function(direction, t){ var to_left = to.left
var v = direction == 'top' ? 'y' : 'x' var speen_x = speed.x
if(Math.abs(dist[direction]) >= 1){ var speen_y = speed.y
d = ((t - start) * speed[v]) var from_top = from.top
if(Math.abs(dist[direction]) > Math.abs(d)){ var from_left = from.left
dist[direction] -= d var cur_top = from_top
cur[direction] = Math.round(cur[direction] + d) var cur_left = form_left
// normalize... var dist_top = to_top - from_top
cur[direction] = Math.abs(dist[direction]) <= 1 ? to[direction] : cur[direction] var dist_left = to_left - from_left
// calc speed for next step...
speed[v] = dist[direction] / (duration - (t - start))
} else {
cur[direction] = to[direction]
}
}
}
*/
var runner = animationFrameRunner(function(){ var runner = animationFrameRunner(function(){
var t = Date.now() var t = Date.now()
@ -517,44 +501,46 @@ function animateElementTo2(elem, to, duration, easing, speed, use_transitions){
// calculate target position for current step... // calculate target position for current step...
// XXX do propper easing... // XXX do propper easing...
if(speed != null){ if(speed != null){
//_shift('top', t) // NOTE: these are inlined here for speed...
//_shift('left', t) if(Math.abs(dist_top) >= 1){
if(Math.abs(dist.top) >= 1){ dy = ((t - start) * speed_y)
dy = ((t - start) * speed.y) if(Math.abs(dist_top) > Math.abs(dy)){
if(Math.abs(dist.top) > Math.abs(dy)){ dist_top -= dy
dist.top -= dy cur_top = Math.round(cur_top + dy)
cur.top = Math.round(cur.top + dy)
// normalize... // 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... // calc speed for next step...
speed.y = dist.top / (duration - (t - start)) speed_y = dist_top / (duration - (t - start))
} else { } else {
cur.top = to.top cur_top = to_top
} }
} }
if(Math.abs(dist.left) >= 1){ if(Math.abs(dist_left) >= 1){
dx = ((t - start) * speed.x) dx = ((t - start) * speed_x)
if(Math.abs(dist.left) > Math.abs(dx)){ if(Math.abs(dist_left) > Math.abs(dx)){
dist.left -= dx dist_left -= dx
cur.left = Math.round(cur.left + dx) cur_left = Math.round(cur_left + dx)
// normalize... // 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... // calc speed for next step...
speed.x = dist.left / (duration - (t - start)) speed_x = dist_left / (duration - (t - start))
} else { } else {
cur.left = to.left cur_left = to_left
} }
} }
// liner speed... // liner speed...
} else { } else {
var r = (t - start) / duration var r = (t - start) / duration
cur.top = Math.round(from.top + (dist.top * r)) cur_top = Math.round(from_top + (dist_top * r))
cur.left = Math.round(from.left + (dist.left * r)) cur_left = Math.round(from_left + (dist_left * r))
} }
// do the actual move... // do the actual move...
setElementTransform(elem, cur) setElementTransform(elem, {
top: cur_top,
left: cur_left
})
}) })
elem.data('animating', runner) elem.data('animating', runner)