Paginator is a jQuery plug-in to spread a number of items over various pages. The items to be paginated must be within a container element (for example, a div
), upon which the plug-in is called. If the settings provided to the plug-in mean that more than one page is neccessary, it inserts a ul
element immediately after the container which contains at least six li
elements; buttons to go to the first page, the last page, the previous page, the next page, and each individual page between.
- Add
jquery.paginator.js
to your project, along with jQuery and hashchange. - Add your items to your page, with a container element.
- Add the following jQuery to your page, to be executed on load:
$('#pgn-container').paginator();
...where #pgn-container
is a selector for the item container.
A demo is available in demo.html.
Additional settings can be used to customise Paginator, and should be added as a parameter within curly braces:
itemsPerPage
: How many items appear per page (default6
; must be any integer greater than0
).keyboardNavigation
: Whether the pages can be traversed using the left and right arrow keys (defaulttrue
; must be boolean).prevButtonContent
: The contents of the previous pageli
element (default<
; must be a string).nextButtonContent
: The contents of the next pageli
element (default>
; must be a string).firstButtonContent
: The contents of the first pageli
element (default<<
; must be a string).lastButtonContent
: The contents of the last pageli
element (default>>
; must be a string).pageButtonClass
: A custom class name for page buttonli
elements (defaultfalse
; must be booleanfalse
or a string).fadeRate
: The rate at which pages fade in and out (default0
; must be an integer greater than or equal to0
or the strings'fast'
or'slow'
).fixedHeight
: Whether or not the page container has a fixed height (defaultfalse
; must be boolean).heightDivisor
: A number to divideitemsPerPage
(set above) by before multiplying it with the items' height. This value is used as the height of the container whenfixedHeight
(set above) istrue
(default1
; must be a number).
An example of these in practice:
$('#pgn-container').paginator({
'itemsPerPage' : 4
});
Paginator adds the page picker elements as li
elements within a ul
. You can easily customise it using rules for ul#pgn-page-list
(items within this list are named li#pgn-page-picker-previous
, li#pgn-page-picker-next
, li#pgn-page-picker-first
, li#pgn-page-picker-last
and li#pgn-page-picker-x
, where x
is the page number).
- Double-clicking the next or previous page buttons, or clicking adjacent page numbers in quick succession can cause the elements of two pages to be loaded onto the page. This only occurs when
fadeRate
is set to a value higher than about80
, although it depends how quickly the user can click.
- Written by Chris Cook