Infinite Scroll

Automatically add next page

README

Infinite Scroll


_Automatically add next page_

See infinite-scroll.com for complete docs and demos.

Install


Download



CDN


Link directly to Infinite Scroll files on unpkg.

  1. ``` html
  2. <script src="https://unpkg.com/infinite-scroll@4/dist/infinite-scroll.pkgd.min.js"></script>
  3. <script src="https://unpkg.com/infinite-scroll@4/dist/infinite-scroll.pkgd.js"></script>
  4. ```

Package managers


npm: npm install infinite-scroll

Yarn: yarn add infinite-scroll

License


Commercial license


If you want to use Infinite Scroll to develop commercial sites, themes, projects, and applications, the Commercial license is the appropriate license. With this option, your source code is kept proprietary. Purchase an Infinite Scroll Commercial License at infinite-scroll.com

Open source license


If you are creating an open source application under a license compatible with the GNU GPL license v3, you may use Infinite Scroll under the terms of the GPLv3.


Usage


Infinite Scroll works on a container element with its child item elements

  1. ``` html
  2. <div class="container">
  3.   <article class="post">...</article>
  4.   <article class="post">...</article>
  5.   <article class="post">...</article>
  6.   ...
  7. </div>
  8. ```

Options


  1. ``` js
  2. let infScroll = new InfiniteScroll( '.container', {
  3.   // defaults listed

  4.   path: undefined,
  5.   // REQUIRED. Determines the URL for the next page
  6.   // Set to selector string to use the href of the next page's link
  7.   // path: '.pagination__next'
  8.   // Or set with {{#}} in place of the page number in the url
  9.   // path: '/blog/page/{{#}}'
  10.   // or set with function
  11.   // path: function() {
  12.   //   return return '/articles/P' + ( ( this.loadCount + 1 ) * 10 );
  13.   // }

  14.   append: undefined,
  15.   // REQUIRED for appending content
  16.   // Appends selected elements from loaded page to the container

  17.   checkLastPage: true,
  18.   // Checks if page has path selector element
  19.   // Set to string if path is not set as selector string:
  20.   //   checkLastPage: '.pagination__next'

  21.   prefill: false,
  22.   // Loads and appends pages on intialization until scroll requirement is met.

  23.   responseBody: 'text',
  24.   // Sets the method used on the response.
  25.   // Set to 'json' to load JSON.

  26.   domParseResponse: true,
  27.   // enables parsing response body into a DOM
  28.   // disable to load flat text

  29.   fetchOptions: undefined,
  30.   // sets custom settings for the fetch() request
  31.   // for setting headers, cors, or POST method
  32.   // can be set to an object, or a function that returns an object

  33.   outlayer: false,
  34.   // Integrates Masonry, Isotope or Packery
  35.   // Appended items will be added to the layout

  36.   scrollThreshold: 400,
  37.   // Sets the distance between the viewport to scroll area
  38.   // for scrollThreshold event to be triggered.

  39.   elementScroll: false,
  40.   // Sets scroller to an element for overflow element scrolling

  41.   loadOnScroll: true,
  42.   // Loads next page when scroll crosses over scrollThreshold

  43.   history: 'replace',
  44.   // Changes the browser history and URL.
  45.   // Set to 'push' to use history.pushState()
  46.   //    to create new history entries for each page change.

  47.   historyTitle: true,
  48.   // Updates the window title. Requires history enabled.

  49.   hideNav: undefined,
  50.   // Hides navigation element

  51.   status: undefined,
  52.   // Displays status elements indicating state of page loading:
  53.   // .infinite-scroll-request, .infinite-scroll-load, .infinite-scroll-error
  54.   // status: '.page-load-status'

  55.   button: undefined,
  56.   // Enables a button to load pages on click
  57.   // button: '.load-next-button'

  58.   onInit: undefined,
  59.   // called on initialization
  60.   // useful for binding events on init
  61.   // onInit: function() {
  62.   //   this.on( 'append', function() {...})
  63.   // }

  64.   debug: false,
  65.   // Logs events and state changes to the console.
  66. })
  67. ```

Browser support


Infinite Scroll v4 supports Chrome 60+, Edge 79+, Firefox 55+, Safari 11+.

For IE10 and Android 4 support, try Infinite Scroll v3.

Development


This package is developed with Node.js v14 and npm v6. Manage Node and npm version with nvm.

  1. ``` sh
  2. nvm use
  3. ```

Install dependencies

  1. ``` sh
  2. npm install
  3. ```

Lint

  1. ``` sh
  2. npm run lint
  3. ```

Run tests

  1. ``` sh
  2. npm test
  3. ```