1.3.5 • Published 6 years ago

infinite-scroll-loading v1.3.5

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Infinite-Scroll

Apply infinite scroll to your website or web-app.

How to start

  • npm install infinite-scroll-loading --save
  • import the normal or minified version from the dist directory.

How to use

InfiniteScroll(config)

Config

KeyTypeDefaultValueDataAttributeRequired
containerDOMElementdocument.bodynullfalse
scrollTargetDOMElementthis.containernullfalse
urlStringnulldata-urltrue
requestObject{data : "", method : "GET"}nullfalse
request.dataObject or Function""nullfalse
request.methodString"GET"data-methodfalse
loadingDOMString or DOMElement"<div class="infinite-scroll__loading"> Loading... </div>"nullfalse
moreButtonDOMElementnullnullfalse
marginNumber500data-marginfalse
onLoadFunctionnullnullfalse
onRenderFunctionnullnullfalse

Docs

  • container: The target element that the infinite scroll should be applied to.
  • scrollTarget: The element on which the scroll listener must be added to. If it is not specified the element will be the container.
  • url: The url that the request must be sent to.
  • request.data: The data to be sent via the request. It must be a single-level key-value Object or a Function returning an Object.
  • request.method: The method of the request. By default it is GET.
  • loading: The loading element. The loading element must have the class infinite-scroll__loading.
  • moreButton: The button that loads the next set of data. If moreButton is specified, the scroll listener will be disabled.
  • margin: The scroll margin on which the request of the next set of data must be sent. The value is in pixels from the bottom of the scrollTop.
  • onLoad: A callback function to be called after the next set of data is acquired. It has the response as its parameter and the context of the function is the container element. By default if the onLoad method is not specified, it gets the response and appends it to the container.
  • onRender: A callback function to be called after the next set of data is rendered.
Methods
  • allDataLoaded: A method to say that all the data is loaded and no requests must be sent anymore.

    Usage:

      infiniteScrollInstance.allDataLoaded(true) //to specify that all the data is loaded
      infiniteScrollInstance.allDataLoaded(false) //to specify that all the data is not loaded
  • unbind: A method to unbind the infinite scroll from the container.

    Usage:

      infiniteScrollInstance.unbind()

Tricks

If you want to let the infinite scroll know that there are no more items to load and prevent it from sending requests again, you can set x-last-page header on your response from the server or return an empty string as the response.

License

This project is licensed under the MIT License.

1.3.5

6 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.5

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago