This is a jQuery plugin for laying out a dynamic grid of elements.
See the documentation page for examples.
The repository also includes many functional examples. All images used in the example are copyrighted by their respective owners and only included for showcasing plugin functionality.
Do you like this project? Buy me a beer
- jQuery - 1.4.3 or better
Copy jquery.wookmark.js
to your javascript folder.
The plugin can be called with jQuery in different ways.
$('.myElements').wookmark();
Where myElement
is the class of the items you want to lay out in a grid.
$('.myElements').wookmark({
align: 'center',
autoResize: false,
comparator: null,
container: $('body'),
direction: undefined,
ignoreInactiveItems: true,
itemWidth: 0,
fillEmptySpace: false,
flexibleWidth: 0,
offset: 2,
onLayoutChanged: undefined,
outerOffset: 0,
resizeDelay: 50
});
See the documentation page for details on available options.
These values can be given as numbers which will be interpreted as pixels or you can use percentage strings like '20%'.
When flexibleWidth
is set an itemWidth
!= 0 is used as minimum item width. As example using a flexibleWidth
of 40% will result in two columns with 10% space to the sides of the container.
Elements which are hidden have cannot be laid out until they are visible. If you use wookmark on a hidden tab layout will not be immediately performed. When the tab is made visible you can manually refresh wookmark using a trigger on your container.
$('#myContent').trigger('refreshWookmark');
This creates placeholders at the bottom of each column to create an even layout. See example-placeholder
on how to use it. These placeholders use the css class wookmark-placeholder
. You can overwrite it in your own css to fit your needs.
When set to false
inactive items will still be shown when filtered. This can be used to fade out filtered items. See the example-filter/fade.html example.
You can use this option to provide a custom comparator function which the plugin will use to sort the tiles. See example-sort or example-stamp on how to use it.
Is the preferred setup. In this scenario the width and height of all images is set in the HTML img attributes. The grid layout can be performed as soon as the document is rendered, BEFORE images are loaded.
In this example, the width and height of the images is not known. Via Paul Irish's imagesLoaded plugin (slightly modified by desandro). The grid layout is performed after all images are loaded and their dimensions can be retrieved. This approach is much slower. The imagesLoaded plugin can also be found on github right here: https://gist.github.com/797120
This example shows how to load and initialize the plugin when using require.js
or a different amd loading method.
This example shows how to load the tile data from a remote api and layout it.
This example shows how to add new tiles at runtime and refresh the layout.
This example shows to use the filter
feature of the plugin to show just the tiles the user wants.
This example shows how to use the flexibleWidth
option. This option allows your tiles to grow a certain amount, as long as there is room. When using percentage values for the width options you can create a fixed column count layout.
This example shows you how to include a lightbox.
This example shows you how to enable placeholders at the bottom of the tile layout to create an even footer.
This example shows how the sort
feature works. This option allows you to specify a sorting function which will rearrange your tiles.
For example you can use it to sort your tiles containing products by price, popularity or name.
You should use the 'imagesloaded' plugin. Most the examples in this package include the code how to use it.
Use the 'finished'-callback of your animation/effect to trigger 'refreshWookmark' on the container element supplied to the plugin.
Set 'position: relative' on your container element and check if there are other elements in the container before your tiles.
Send us some feedback or create an issue on github.
Please send code specific questions and feedback to Sebastian or contact him on twitter.
If you have other questions and feedback which is for example related to Wookmark send a mail to Christoph or contact him on twitter.
Contribute!