A pure logic component for scrolling/zooming. It is independent of any specific kind of rendering or event system.
The "demo" folder contains examples for usage with DOM and Canvas renderings which works both, on mouse and touch driven devices.
See our demos online here: http://zynga.github.com/scroller/
These are the available options with their defaults. Options can be modified using the second constructor parameter or during runtime by modification of scrollerObj.options.optionName
.
true
true
true
250
true
true
false
false
false
0.5
3
Callback (first parameter of constructor) is required. Options are optional. Defaults are listed above. The created instance must have proper dimensions using a setDimensions()
call. Afterwards you can pass in event data or manually control scrolling/zooming via the API.
var scrollerObj = new Scroller(function(left, top, zoom) {
// apply coordinates/zooming
}, {
scrollingY: false
});
// Configure to have an outer dimension of 1000px and inner dimension of 3000px
scrollerObj.setDimensions(1000, 1000, 3000, 3000);
scrollerObj.setDimensions(clientWidth, clientHeight, contentWidth, contentHeight);
scrollerObj.setPosition(clientLeft, clientTop);
snapping
is enabled)scrollerObj.setSnapSize(width, height);
scrollerObj.activatePullToRefresh(height, activate, deactivate, start);
scrollerObj.finishPullToRefresh();
scrollerObj.getValues() => { left, top, zoom }
scrollerObj.zoomTo(level, animate ? false, originLeft ? center, originTop ? center)
zoomTo
but by a relative value.scrollerObj.zoomBy(factor, animate ? false, originLeft ? center, originTop ? center);
scrollerObj.scrollTo(left, top, animate ? false);
scrollerObj.scrollBy(leftOffset, topOffset, animate ? false);
This API part can be used to pass event data to the scrollerObj
to react on user actions.
doMouseZoom(wheelDelta, timeStamp, pageX, pageY)
doTouchStart(touches, timeStamp)
doTouchMove(touches, timeStamp, scale)
doTouchEnd(timeStamp)
For a touch device just pass the native touches
event data to the doTouch* methods. On mouse systems one can emulate this data using an array with just one element:
doTouchMove(e.touches, e.timeStamp);
doTouchMove([e], e.timeStamp);
To zoom using the mousewheel
event just pass the data like this:
doMouseZoom(e.wheelDelta, e.timeStamp, e.pageX, e.pageY);
For more information about this please take a look at the demos.