Skip to content

Instantly share code, notes, and snippets.

@jperl
Last active August 29, 2015 14:01
Show Gist options
  • Save jperl/c9df45a0c6e24f338de3 to your computer and use it in GitHub Desktop.
Save jperl/c9df45a0c6e24f338de3 to your computer and use it in GitHub Desktop.
Force a scrollview to a page index
/**
* 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