Last active
August 29, 2015 14:01
-
-
Save jperl/c9df45a0c6e24f338de3 to your computer and use it in GitHub Desktop.
Force a scrollview to a page index
This file contains hidden or 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
/** | |
* Force a scrollview to a position | |
*/ | |
Tools.forcePosition = function (scrollview, position, noSpring) { | |
if (noSpring) { | |
scrollview._springState = 0; | |
scrollview._physicsEngine.detachAll(); | |
} | |
scrollview.setVelocity(0); | |
scrollview.setPosition(position); | |
}; | |
/** | |
* Force a scrollview to a page index. | |
* @param scrollview | |
* @param pageIndex | |
*/ | |
Tools.forcePage = function (scrollview, pageIndex) { | |
var currentNodeIndex = scrollview._node.index; | |
var pageSize = scrollview.options.direction === 0 | |
? scrollview.getSize()[0] | |
: scrollview.getSize()[1]; | |
var distance = (pageIndex - currentNodeIndex) * pageSize; | |
Tools.forcePosition(scrollview, distance); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment