mirror of
https://github.com/flynx/PortableMag.git
synced 2025-10-29 11:10:08 +00:00
testing 2'nd gen animation...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
084d8968c7
commit
11e4360d0c
30
lib/jli.js
30
lib/jli.js
@ -408,6 +408,7 @@ function setElementTransform(elem, offset, scale, duration){
|
|||||||
function animationFrameRunner(func){
|
function animationFrameRunner(func){
|
||||||
var next
|
var next
|
||||||
var _nop = function(){ return this }
|
var _nop = function(){ return this }
|
||||||
|
var frame
|
||||||
|
|
||||||
if(this === window){
|
if(this === window){
|
||||||
self = new animationFrameRunner
|
self = new animationFrameRunner
|
||||||
@ -436,6 +437,10 @@ function animationFrameRunner(func){
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
var stop = function(){
|
var stop = function(){
|
||||||
|
if(frame != null){
|
||||||
|
cancelAnimationFrame(frame)
|
||||||
|
frame = null
|
||||||
|
}
|
||||||
next = _nop
|
next = _nop
|
||||||
this.start = start
|
this.start = start
|
||||||
this.stop = _nop
|
this.stop = _nop
|
||||||
@ -451,10 +456,19 @@ function animationFrameRunner(func){
|
|||||||
|
|
||||||
// NOTE: this is exclusive, e.g. all other animations set with this will
|
// NOTE: this is exclusive, e.g. all other animations set with this will
|
||||||
// be stopped on call...
|
// be stopped on call...
|
||||||
|
// XXX for some reason this is slower that animateElementTo(..) on iPad...
|
||||||
function animateElementTo2(elem, to, duration, easing, speed, use_transitions){
|
function animateElementTo2(elem, to, duration, easing, speed, use_transitions){
|
||||||
use_transitions = use_transitions != null ?
|
use_transitions = use_transitions != null ?
|
||||||
use_transitions
|
use_transitions
|
||||||
: USE_TRANSITIONS_FOR_ANIMATION
|
: 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) ? {
|
to = typeof(to) == typeof(1) ? {
|
||||||
left: to,
|
left: to,
|
||||||
top: 0,
|
top: 0,
|
||||||
@ -490,18 +504,23 @@ function animateElementTo2(elem, to, duration, easing, speed, use_transitions){
|
|||||||
var speed_y = speed.y
|
var speed_y = speed.y
|
||||||
}
|
}
|
||||||
|
|
||||||
var runner = animationFrameRunner(function(){
|
elem.animating = true
|
||||||
var t = Date.now()
|
|
||||||
|
|
||||||
|
var runner = animationFrameRunner(function(t){
|
||||||
// end of the animation...
|
// end of the animation...
|
||||||
if(t >= then){
|
if(t >= then){
|
||||||
setElementTransform(elem, to)
|
setElementTransform(elem, to)
|
||||||
runner.stop()
|
runner.stop()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// animation stopped...
|
||||||
|
if(!elem.animating){
|
||||||
|
setElementTransform(elem, cur)
|
||||||
|
runner.stop()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// calculate target position for current step...
|
// calculate target position for current step...
|
||||||
// XXX do propper easing...
|
|
||||||
if(speed != null){
|
if(speed != null){
|
||||||
// NOTE: these are inlined here for speed...
|
// NOTE: these are inlined here for speed...
|
||||||
if(Math.abs(dist_top) >= 1){
|
if(Math.abs(dist_top) >= 1){
|
||||||
@ -673,7 +692,6 @@ function animateElementTo(elem, to, duration, easing, speed, use_transitions){
|
|||||||
|
|
||||||
|
|
||||||
function stopAnimation(elem){
|
function stopAnimation(elem){
|
||||||
// legacy...
|
|
||||||
if(elem.next_frame){
|
if(elem.next_frame){
|
||||||
cancelAnimationFrame(elem.next_frame)
|
cancelAnimationFrame(elem.next_frame)
|
||||||
elem.next_frame = false
|
elem.next_frame = false
|
||||||
@ -681,8 +699,8 @@ function stopAnimation(elem){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//animateElementTo = animateElementTo2
|
animateElementTo = animateElementTo2
|
||||||
//stopAnimation = stopAnimation2
|
stopAnimation = stopAnimation2
|
||||||
|
|
||||||
|
|
||||||
// XXX account for other transitions...
|
// XXX account for other transitions...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user