Class: LazyPagination {#LazyPagination}

Automatically sends ajax requests as the user scrolls an element. Provides options to control where the response is injected into the DOM (usually above a footer).

Demo:

Extends:

Request.HTML

Example

Set it up just like you would any other pagination on the server. This example is totally simplified.

HTML/PHP Front-page

<body>
  <div id="navigation"> <!-- fallback navigation --> </div>

    <?php include '_page.php'; ?>

    <div id="footer">Blah blah blah</div>
</body>

HTML/PHP Requested partial

You would do something on the server to deliver the next page.

<div class="page">
    <p>I am a page <?php echo $_GET['page']; ?></p>
</div>

JavaScript

var lazy = new LazyPagination(document,{
    url: '_page.php',
    method: 'get',
    maxRequests: 20,
    buffer: 1000,
    data: {
        page: 2 // the first "next page" to request
    },
    pageDataIndex: 'page', // variable in `data` that holds the page number to request
    navigation: 'navigation', // will destroy `navigation` if javascript is enabled
    inject: {
        element: 'footer',
        where: 'before' // will inject pages above the footer
    }
});

LazyPagination Method: constructor {#LazyPagination:constructor}

Syntax:

var myLazyPagination = new LazyPagination(element, options);

Arguments:

  1. element - (mixed) A string of the id for an Element or an Element reference that contains pages and overflow.
  2. options - (obj) The Request.HTML options plus the following:

Options:

Events:

Note:

By default the data option is as follows:

data: { 'page': 2 }

LazyPagination Method: attach {#LazyPagination:attach}

Attaches the scroll event to the element and resize event to the window.

Syntax:

myLazyPagination.attach();

Returns

This LazyPagination instance.

LazyPagination Method: detach {#LazyPagination:detach}

Detaches the scroll event from the element and resize event from the window.

Syntax:

myLazyPagination.detach();

Returns

This LazyPagination instance.