testing 2'nd gen animation...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-02-05 02:41:31 +04:00
parent 084d8968c7
commit 11e4360d0c

View File

@ -408,6 +408,7 @@ function setElementTransform(elem, offset, scale, duration){
function animationFrameRunner(func){
var next
var _nop = function(){ return this }
var frame
if(this === window){
self = new animationFrameRunner
@ -436,6 +437,10 @@ function animationFrameRunner(func){
return this
}
var stop = function(){
if(frame != null){
cancelAnimationFrame(frame)
frame = null
}
next = _nop
this.start = start
this.stop = _nop
@ -451,10 +456,19 @@ function animationFrameRunner(func){
// NOTE: this is exclusive, e.g. all other animations set with this will
// be stopped on call...
// XXX for some reason this is slower that animateElementTo(..) on iPad...
function animateElementTo2(elem, to, duration, easing, speed, use_transitions){
use_transitions = use_transitions != null ?
use_transitions
: USE_TRANSITIONS_FOR_ANIMATION
// use transition for animation...
if(use_transitions){
setTransitionEasing(elem, easing)
duration == null && setTransitionDuration(elem, duration)
setElementTransform(elem, to)
return
}
to = typeof(to) == typeof(1) ? {
left: to,
top: 0,
@ -490,18 +504,23 @@ function animateElementTo2(elem, to, duration, easing, speed, use_transitions){
var speed_y = speed.y
}
var runner = animationFrameRunner(function(){
var t = Date.now()
elem.animating = true
var runner = animationFrameRunner(function(t){
// end of the animation...
if(t >= then){
setElementTransform(elem, to)
runner.stop()
return
}
// animation stopped...
if(!elem.animating){
setElementTransform(elem, cur)
runner.stop()
return
}
// calculate target position for current step...
// XXX do propper easing...
if(speed != null){
// NOTE: these are inlined here for speed...
if(Math.abs(dist_top) >= 1){
@ -673,7 +692,6 @@ function animateElementTo(elem, to, duration, easing, speed, use_transitions){
function stopAnimation(elem){
// legacy...
if(elem.next_frame){
cancelAnimationFrame(elem.next_frame)
elem.next_frame = false
@ -681,8 +699,8 @@ function stopAnimation(elem){
}
}
//animateElementTo = animateElementTo2
//stopAnimation = stopAnimation2
animateElementTo = animateElementTo2
stopAnimation = stopAnimation2
// XXX account for other transitions...