Library for the displaying of an infinite content as a grid of tiles.
new Tiler(element, options);
A jQuery element that will be used as a viewport for the tiles grid.
- sync
Tiles factory function. It is called right after the Tiler initialization, after the binder
element was dragged and after the "refresh" method was called. Takes to arguments
:
- *options*
- tosync - an array of tiles coordinates to sync
- removed - array of tiles coordinates that were removed from the grid
- coords - current grid coordinates (left top visible tile)
-
Include main dependencies on your page.
<script src="http://code.jquery.com/jquery.min.js"></script> <script src="https://raw.github.com/borbit/row.js/master/row.js"></script> <script src="https://raw.github.com/borbit/grid.js/master/grid.js"></script>
-
Include Tiler after main dependencies.
<script src="tiler.js"></script>
-
Include some library to make grid draggable. I use
draggable
from jQuery UI.<script src="http://code.jquery.com/ui/1.8.19/jquery-ui.min.js"></script>
-
Create an instance of
Tiler
passing the element you have to make as a viewport by first argument and options by second. Don't forget to pass required optionstileSize
andsync
. Like this:var tiler = new Tiler($('#viewport'), { tileSize: 200, sync: function(options, callback) { var tosync = options.tosync; tosync.forEach(function(tile) { var img = new Image(); var x = tile[0]; var y = tile[1]; img.onload = function() { callback([[x, y, $('<img/>').attr('src', img.src)]]); }; img.src = 'image_' + x + '_' + y + '.png'; }); } });
-
To make grid draggable just:
tiler.binder.draggable();
Tiler is fully covered by QUnit tests. To run tests
just open the tests/index.html
in a browser.
Tiler may be freely distributed under the MIT license.
Copyright (c) 2011 Serge Borbit <serge.borbit@gmail.com>