mirror of
				https://github.com/flynx/PortableMag.git
				synced 2025-10-31 03:50:16 +00:00 
			
		
		
		
	added basic (brain-dead) manual animation engine...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									a2e61f4145
								
							
						
					
					
						commit
						dbea22817a
					
				| @ -628,7 +628,6 @@ iScroll.prototype = { | |||||||
| 		that.moved = true; | 		that.moved = true; | ||||||
| 		 | 		 | ||||||
| 		if (that.options.useTransition) { | 		if (that.options.useTransition) { | ||||||
| 			console.log('transition move...') |  | ||||||
| 			that._transitionTime(step.time); | 			that._transitionTime(step.time); | ||||||
| 			that._pos(step.x, step.y); | 			that._pos(step.x, step.y); | ||||||
| 			that.animating = false; | 			that.animating = false; | ||||||
| @ -637,12 +636,11 @@ iScroll.prototype = { | |||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 			console.log('animate move...') |  | ||||||
| 
 |  | ||||||
| 		animate = function () { | 		animate = function () { | ||||||
| 			var now = Date.now(), | 			var now = Date.now(), | ||||||
| 				newX, newY; | 				newX, newY; | ||||||
| 
 | 
 | ||||||
|  | 			// XXX check if the step is due and if yes do the next step...
 | ||||||
| 			if (now >= startTime + step.time) { | 			if (now >= startTime + step.time) { | ||||||
| 				that._pos(step.x, step.y); | 				that._pos(step.x, step.y); | ||||||
| 				that.animating = false; | 				that.animating = false; | ||||||
|  | |||||||
| @ -118,7 +118,7 @@ $(document).ready(function(){ | |||||||
| 		//momentum: false, | 		//momentum: false, | ||||||
| 		momentum: true, | 		momentum: true, | ||||||
| 		hScrollbar: false, | 		hScrollbar: false, | ||||||
| 		useTransition: true, | 		//useTransition: true, | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	// XXX stub... | 	// XXX stub... | ||||||
|  | |||||||
							
								
								
									
										101
									
								
								layout.js
									
									
									
									
									
								
							
							
						
						
									
										101
									
								
								layout.js
									
									
									
									
									
								
							| @ -103,6 +103,7 @@ var handleSwipeRight = makeSwipeHandler(nextPage) | |||||||
| // NOTE: this will also handle swipeUp/swopeDown as we do not 
 | // NOTE: this will also handle swipeUp/swopeDown as we do not 
 | ||||||
| //		explicitly bind them...
 | //		explicitly bind them...
 | ||||||
| // XXX restore all the changed values...
 | // XXX restore all the changed values...
 | ||||||
|  | // XXX add an animate loop, to make the browser paint the page better...
 | ||||||
| function handleScrollRelease(evt, data){ | function handleScrollRelease(evt, data){ | ||||||
| 	/* | 	/* | ||||||
| 	// this makes things snap...
 | 	// this makes things snap...
 | ||||||
| @ -123,6 +124,7 @@ function handleScrollRelease(evt, data){ | |||||||
| 	var to = (at + (t*speed*INNERTIA_SCALE)) | 	var to = (at + (t*speed*INNERTIA_SCALE)) | ||||||
| 	var first = getMagazineOffset(pages.first(), null, 'center') | 	var first = getMagazineOffset(pages.first(), null, 'center') | ||||||
| 	var last = getMagazineOffset(pages.last(), null, 'center') | 	var last = getMagazineOffset(pages.last(), null, 'center') | ||||||
|  | 	var easing | ||||||
| 
 | 
 | ||||||
| 	// filter out really small speeds...
 | 	// filter out really small speeds...
 | ||||||
| 	if(Math.abs(speed) > 0.5){ | 	if(Math.abs(speed) > 0.5){ | ||||||
| @ -134,23 +136,22 @@ function handleScrollRelease(evt, data){ | |||||||
| 			var _t = t | 			var _t = t | ||||||
| 			t = Math.abs(t * ((at-first)/(at-to))) | 			t = Math.abs(t * ((at-first)/(at-to))) | ||||||
| 			to = first | 			to = first | ||||||
| 			//setTransitionEasing(mag, 'linear')
 | 			//easing = 'linear'
 | ||||||
| 			setTransitionEasing(mag, 'cubic-bezier(0.33,0.66,0.66,1)') | 			easing = 'cubic-bezier(0.33,0.66,0.66,1)' | ||||||
| 		} else if(to < last){ | 		} else if(to < last){ | ||||||
| 			// trim the time proportionally...
 | 			// trim the time proportionally...
 | ||||||
| 			var _t = t | 			var _t = t | ||||||
| 			t = Math.abs(t * ((at-last)/(at-to))) | 			t = Math.abs(t * ((at-last)/(at-to))) | ||||||
| 			to = last | 			to = last | ||||||
| 			//setTransitionEasing(mag, 'linear')
 | 			//easing = 'linear'
 | ||||||
| 			setTransitionEasing(mag, 'cubic-bezier(0.33,0.66,0.66,1)') | 			easing = 'cubic-bezier(0.33,0.66,0.66,1)' | ||||||
| 
 | 
 | ||||||
| 		} else { | 		} else { | ||||||
| 			//setTransitionEasing(mag, 'ease-out')
 | 			//easing = 'ease-out'
 | ||||||
| 			setTransitionEasing(mag, 'cubic-bezier(0.33,0.66,0.66,1)') | 			easing = 'cubic-bezier(0.33,0.66,0.66,1)' | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		setTransitionDuration(mag, t) | 		animateElementTo(mag, to, t, easing) | ||||||
| 		setElementTransform(mag, to) |  | ||||||
| 
 | 
 | ||||||
| 		// restore defaults...
 | 		// restore defaults...
 | ||||||
| 		// XXX this is a bit dumb at this point...
 | 		// XXX this is a bit dumb at this point...
 | ||||||
| @ -165,21 +166,89 @@ function handleScrollRelease(evt, data){ | |||||||
| 	// do not let the user scroll out of view...
 | 	// do not let the user scroll out of view...
 | ||||||
| 	} else { | 	} else { | ||||||
| 		if(at > first){ | 		if(at > first){ | ||||||
| 			//setTransitionEasing(mag, 'ease-in')
 | 			//animateElementTo(mag, first, DEFAULT_TRANSITION_DURATION, 'ease-in')
 | ||||||
| 			setTransitionEasing(mag, 'cubic-bezier(0.33,0.66,0.66,1)') | 			animateElementTo(mag, first, DEFAULT_TRANSITION_DURATION, 'cubic-bezier(0.33,0.66,0.66,1)') | ||||||
| 			setTransitionDuration(mag, DEFAULT_TRANSITION_DURATION/2) |  | ||||||
| 			setElementTransform(mag, first) |  | ||||||
| 
 | 
 | ||||||
| 		} else if(at < last){ | 		} else if(at < last){ | ||||||
| 			//setTransitionEasing(mag, 'ease-in')
 | 			//animateElementTo(mag, last, DEFAULT_TRANSITION_DURATION, 'ease-in')
 | ||||||
| 			setTransitionEasing(mag, 'cubic-bezier(0.33,0.66,0.66,1)') | 			animateElementTo(mag, last, DEFAULT_TRANSITION_DURATION, 'cubic-bezier(0.33,0.66,0.66,1)') | ||||||
| 			setTransitionDuration(mag, DEFAULT_TRANSITION_DURATION/2) |  | ||||||
| 			setElementTransform(mag, last) |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | var USE_TRANSITIONS_FOR_ANIMATION = false | ||||||
|  | 
 | ||||||
|  | var animationFrame = function(){ | ||||||
|  |   return (window.requestAnimationFrame | ||||||
|  | 		  || window.webkitRequestAnimationFrame  | ||||||
|  | 		  || window.mozRequestAnimationFrame | ||||||
|  | 		  || window.oRequestAnimationFrame | ||||||
|  | 		  || window.msRequestAnimationFrame | ||||||
|  | 		  || function(callback){ window.setTimeout(callback, 1000 / 60) }) | ||||||
|  | }() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | function animateElementTo(elem, to, duration, easing){ | ||||||
|  | 	// use transition for animation...
 | ||||||
|  | 	if(USE_TRANSITIONS_FOR_ANIMATION){ | ||||||
|  | 		setTransitionEasing(elem, easing) | ||||||
|  | 		setTransitionDuration(elem, duration) | ||||||
|  | 		setElementTransform(elem, to) | ||||||
|  | 
 | ||||||
|  | 	// manually animate...
 | ||||||
|  | 	} else { | ||||||
|  | 		if(typeof(to) == typeof(1)){ | ||||||
|  | 			to = { | ||||||
|  | 				left: to, | ||||||
|  | 				top: 0, | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		setTransitionDuration(elem, 0) | ||||||
|  | 		var now = Date.now() | ||||||
|  | 		var then = now + duration | ||||||
|  | 		var from = getElementShift(elem) | ||||||
|  | 		var dist = { | ||||||
|  | 			top: to.top - from.top, | ||||||
|  | 			left: to.left - from.left, | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		function animate(t){ | ||||||
|  | 			/* | ||||||
|  | 			// XXX check if we are interrupted...
 | ||||||
|  | 			if(scroller.animating){ | ||||||
|  | 				return | ||||||
|  | 			} | ||||||
|  | 			*/ | ||||||
|  | 
 | ||||||
|  | 			// set position for current step...
 | ||||||
|  | 			if(t < then){ | ||||||
|  | 				var rem = then - t | ||||||
|  | 				var r = rem/duration | ||||||
|  | 
 | ||||||
|  | 				// this is brain-dead linear spacing...
 | ||||||
|  | 				// XXX revise...
 | ||||||
|  | 				var pos = { | ||||||
|  | 					top: to.top - (dist.top * r), | ||||||
|  | 					left: to.left - (dist.left * r), | ||||||
|  | 				} | ||||||
|  | 				 | ||||||
|  | 				setElementTransform(elem, pos) | ||||||
|  | 
 | ||||||
|  | 			// finishup the animation...
 | ||||||
|  | 			} else if(t > then){ | ||||||
|  | 				setElementTransform(elem, to) | ||||||
|  | 				return | ||||||
|  | 			} | ||||||
|  | 			// sched next frame...
 | ||||||
|  | 			animationFrame(animate) | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		animate() | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| /********************************************************* helpers ***/ | /********************************************************* helpers ***/ | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user