Created
September 15, 2014 20:26
-
-
Save solomon-gumball/3eeee3b61090e24e92b7 to your computer and use it in GitHub Desktop.
A basic pauseable transitionable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function(require, exports, module) { | |
var Transitionable = require('famous/transitions/Transitionable'); | |
function CustomTransitionable() { | |
Transitionable.apply(this, arguments); | |
} | |
CustomTransitionable.prototype = Object.create(Transitionable.prototype); | |
CustomTransitionable.prototype.constructor = CustomTransitionable; | |
CustomTransitionable.prototype.pause = function pause () { | |
if(!this.isActive()) return; | |
this.pausedDestination = this.currentAction[0]; | |
this.pausedTransition = _getpausedTransition.call(this, this.currentAction); | |
this.pausedCallback = this._callback; | |
this.halt(); | |
} | |
CustomTransitionable.prototype.resume = function resume () { | |
if(this.pausedDestination) { | |
this.set(this.pausedDestination, this.pausedTransition, this.pausedCallback); | |
} | |
this.pausedDestination = null; | |
this.pausedTransition = null; | |
this.pausedCallback = null; | |
} | |
function _getpausedTransition (currentAction) { | |
var progress; | |
var currentState = this.get(); | |
var adjustedTransition; | |
// if transitioning an array simply look at first element in array. | |
if (Array.isArray(currentState)) progress = currentState[0] / currentAction[0][0]; | |
else progress = currentState / currentAction[0]; | |
// adjust transition based on current progress. | |
adjustedTransition = currentAction[1]; | |
adjustedTransition.duration = adjustedTransition.duration * (1 - progress); | |
return adjustedTransition; | |
} | |
module.exports = CustomTransitionable; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment