Accelerated panning and zooming for HTML and Canvas
JavaScript
3,916
64 commits
updated Nov 21, 2025
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://pbakaus.github.io/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.
truetruetrue250truetruefalsefalsefalse0.53Modern (npm):
npm install scroller
CDN (vanilla JS):
<!-- Full bundle (recommended) -->
<script src="https://unpkg.com/scroller/dist/scroller-full.min.js"></script>
<!-- Core only -->
<script src="https://unpkg.com/scroller/dist/scroller.min.js"></script>
ES6 Modules:
import { Scroller } from 'scroller';
CommonJS:
const { Scroller } = require('scroller');
Vanilla JS:
// Available as global Scroller after loading script
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);
EasyScroller (Simplified API):
EasyScroller provides a simplified, DOM-focused API that automatically handles scrolling and zooming for elements with data attributes.
Auto-initialization:
EasyScroller automatically initializes on elements with data-scrollable or data-zoomable attributes when the DOM is ready.
<!-- Auto-initialized scrollable container -->
<div data-scrollable="y">
<div>Your content here</div>
</div>
<!-- Auto-initialized zoomable container -->
<div data-zoomable="true">
<div>Your zoomable content here</div>
</div>
Manual initialization:
// ES6 Modules
import { EasyScroller } from 'scroller';
// Vanilla JS (full bundle only)
const easyScroller = new Scroller.EasyScroller(containerElement, options);
// Basic usage
const container = document.getElementById('my-container');
const easyScroller = new EasyScroller(container, {
scrollingX: true,
scrollingY: true,
zooming: true
});
DOM Structure Requirements: EasyScroller requires a specific DOM structure where the container element (with data attributes or passed to constructor) contains exactly one child element that holds the actual content:
<div data-scrollable="true"> <!-- Container -->
<div> <!-- Content wrapper (required) -->
<!-- Your actual content here -->
</div>
</div>
Data Attribute Options:
data-scrollable="true" - Enable scrolling on both axesdata-scrollable="x" - Enable horizontal scrolling onlydata-scrollable="y" - Enable vertical scrolling onlydata-zoomable="true" - Enable zooming with default range (0.5x to 3x)data-zoomable="min-max" - Enable zooming with custom range (e.g., "0.5-2")EasyScroller API:
// Scroll to position
easyScroller.scrollTo(left, top, animate);
// Zoom to level
easyScroller.zoomTo(level, animate, originLeft, originTop);
// Get current values
const values = easyScroller.getValues(); // { left, top, zoom }
// Clean up
easyScroller.destroy();
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.
2,432 followers · starred Sep 2011
9,748 followers · starred Apr 2023
968 followers · starred Sep 2011
6,078 followers · starred Sep 2013
Accelerated panning and zooming for HTML and Canvas
JavaScript
3,916
64 commits
updated Nov 21, 2025
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://pbakaus.github.io/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.
truetruetrue250truetruefalsefalsefalse0.53Modern (npm):
npm install scroller
CDN (vanilla JS):
<!-- Full bundle (recommended) -->
<script src="https://unpkg.com/scroller/dist/scroller-full.min.js"></script>
<!-- Core only -->
<script src="https://unpkg.com/scroller/dist/scroller.min.js"></script>
ES6 Modules:
import { Scroller } from 'scroller';
CommonJS:
const { Scroller } = require('scroller');
Vanilla JS:
// Available as global Scroller after loading script
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);
EasyScroller (Simplified API):
EasyScroller provides a simplified, DOM-focused API that automatically handles scrolling and zooming for elements with data attributes.
Auto-initialization:
EasyScroller automatically initializes on elements with data-scrollable or data-zoomable attributes when the DOM is ready.
<!-- Auto-initialized scrollable container -->
<div data-scrollable="y">
<div>Your content here</div>
</div>
<!-- Auto-initialized zoomable container -->
<div data-zoomable="true">
<div>Your zoomable content here</div>
</div>
Manual initialization:
// ES6 Modules
import { EasyScroller } from 'scroller';
// Vanilla JS (full bundle only)
const easyScroller = new Scroller.EasyScroller(containerElement, options);
// Basic usage
const container = document.getElementById('my-container');
const easyScroller = new EasyScroller(container, {
scrollingX: true,
scrollingY: true,
zooming: true
});
DOM Structure Requirements: EasyScroller requires a specific DOM structure where the container element (with data attributes or passed to constructor) contains exactly one child element that holds the actual content:
<div data-scrollable="true"> <!-- Container -->
<div> <!-- Content wrapper (required) -->
<!-- Your actual content here -->
</div>
</div>
Data Attribute Options:
data-scrollable="true" - Enable scrolling on both axesdata-scrollable="x" - Enable horizontal scrolling onlydata-scrollable="y" - Enable vertical scrolling onlydata-zoomable="true" - Enable zooming with default range (0.5x to 3x)data-zoomable="min-max" - Enable zooming with custom range (e.g., "0.5-2")EasyScroller API:
// Scroll to position
easyScroller.scrollTo(left, top, animate);
// Zoom to level
easyScroller.zoomTo(level, animate, originLeft, originTop);
// Get current values
const values = easyScroller.getValues(); // { left, top, zoom }
// Clean up
easyScroller.destroy();
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.
2,432 followers · starred Sep 2011
9,748 followers · starred Apr 2023
968 followers · starred Sep 2011
6,078 followers · starred Sep 2013