some fixes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-02-05 02:26:34 +04:00
parent d81a8179b6
commit f9c3c87b10

View File

@ -595,6 +595,7 @@ function animateElementTo(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
@ -603,6 +604,24 @@ function animateElementTo(elem, to, duration, easing, speed, use_transitions){
top: to.top - from.top,
left: to.left - from.left,
}
*/
// do var caching...
var to_top = to.top
var to_left = to.left
var from_top = from.top
var from_left = from.left
var cur_top = from_top
var cur_left = from_left
var dist_top = to_top - from_top
var dist_left = to_left - from_left
if(speed != null){
var speed_x = speed.x
var speed_y = speed.y
}
// XXX are we using this...
elem.animating = true
elem.next_frame = null
@ -623,14 +642,51 @@ function animateElementTo(elem, to, duration, easing, speed, use_transitions){
return
}
// do an intermediate step...
// XXX do proper easing...
// XXX sometimes results in jumping around...
// ...result of jumping over the to position...
if(speed != null){
// 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
// 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
}
}
// XXX the following two blocks are the same...
// XXX looks a bit too complex, revise...
// 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))
}
// do the actual move...
setElementTransform(elem, {
top: cur_top,
left: cur_left
})
/*
// animate a step with speed...
if(speed != null){
// NOTE: these are almost identical, they are inlined
// for speed...
if(Math.abs(dist.top) >= 1){
dy = ((t - start) * speed.y)
if(Math.abs(dist.top) > Math.abs(dy)){
@ -644,8 +700,6 @@ function animateElementTo(elem, to, duration, easing, speed, use_transitions){
cur.top = to.top
}
}
// XXX looks a bit too complex, revise...
if(Math.abs(dist.left) >= 1){
dx = ((t - start) * speed.x)
if(Math.abs(dist.left) > Math.abs(dx)){
@ -660,13 +714,15 @@ function animateElementTo(elem, to, duration, easing, speed, use_transitions){
}
}
// XXX this is a straight forward linear function...
// liner animate...
} else {
var r = (t - start) / duration
cur.top = Math.round(from.top + (dist.top * r))
cur.left = Math.round(from.left + (dist.left * r))
}
setElementTransform(elem, cur)
*/
// sched next frame...
elem.next_frame = getAnimationFrame(animate)
}