let ias = new InfiniteAjaxScroll(/*..*/, {
next: '.pager__next',
prev: '.pager__prev'
})
pagination
Type:boolean|string|ElementDefault:falseRequired: no
Selector of the elements that contain the pagination. The elements that match the selector will be hidden (element.style.display -> none) when Infinite Ajax Scroll binds.
let ias = new InfiniteAjaxScroll(/*..*/, {
// pass pagination as selector:
pagination: '.pager',
// or pass pagination as Element:
pagination: document.getElementById('pager1'),
// or pass false explicitly to disable automatic hiding:
pagination: false,
})
responseType
Type:stringDefault:"document"Required: no
Type of response. Can be set to "json".
let ias = new InfiniteAjaxScroll(/*..*/, {
responseType: 'json'
})
bind
Type:booleanDefault:trueRequired: no
scrollContainer
Type:string|Element|windowDefault:windowRequired: no
Set a selector of the element you want to use as a scroll container. Use this if you want infinite scroll inside an overflow element.
Note: Only a single element should match the selector.
let ias = new InfiniteAjaxScroll('.container', {
scrollContainer: '#scroller'
})
negativeMargin
Type:int (pixels)
Default:0Required: no
By default Infinite Ajax Scroll starts loading new items when the user scrolls to the bottom of the last item. The negativeMargin (in pixels) will be subtracted from the items' offset, allowing you to load new pages sooner.
This value is always transformed to a positive integer (a value of -100 will behave the same as 100)
User experience can degrade when new pages are loaded too quickly without visual feedback. Use with caution.
let ias = new InfiniteAjaxScroll(/*..*/, {
// start loading the next page when the user scrolls to (or passed) 400px before the end of the last item
negativeMargin: 400
})
spinner
Type:string|Element|Object|booleanDefault:falseRequired: no
Configures a spinner/loader. By default no spinner is configured.
You can set a selector to an element you want to display when Infinite Ajax Scroll is loading the next page.
let ias = new InfiniteAjaxScroll(/*..*/, {
spinner: '.spinner',
// alternatively we can pass an Element
spinner: document.getElementById('spinner1'),
})
You can also set advanced spinner options.
let ias = new InfiniteAjaxScroll(/*..*/, {
spinner: {
// element to show as spinner
element: '.spinner',
// delay in milliseconds
// this is the minimal time the loader should be displayed. If loading takes longer, the spinner
// will be shown for the duration of the loading. If the loading takes less then this duration,
// say 300ms, then the spinner is still shown for 600ms.
delay: 600,
// this function is called when the button has to be shown
show: function(element) {
element.style.opacity = '1'; // default behaviour
},
// this function is called when the button has to be hidden
hide: function(element) {
element.style.opacity = '0'; // default behaviour
}
}
})
trigger
Type:string|Element|Object|booleanDefault:falseRequired: no
Configures a trigger. By default no trigger is configured.
You can use the selector of an element you want to use as a trigger.
let ias = new InfiniteAjaxScroll(/*..*/, {
trigger: '.trigger',
// alternatively we can pass an Element
trigger: document.getElementById('trigger1'),
// we can also pass a factory function to create an Element
trigger: function() {
let el = document.createElement('button');
el.innerText = 'Load More...';
document.querySelector('.some_parent_class').appendChild(el);
// we have to return the element so IAS can add the necessary event listeners
return el;
},
})
We can also set advanced trigger options.
let ias = new InfiniteAjaxScroll(/*..*/, {
trigger: {
// element to show as trigger
element: '.trigger',
// pass a function which returns true which determines if the load more button should be shown
when: function(pageIndex) {
return true; // default behaviour (always show a trigger)
},
// this function is called when the button has to be shown
show: function(element) {
element.style.opacity = '1'; // default behaviour
},
// this function is called when the button has to be hidden
hide: function(element) {
element.style.opacity = '0'; // default behaviour
}
}
})
logger
Configure an event logger.
let ias = new InfiniteAjaxScroll(/*..*/, {
logger: true
})
To disable the logger you can pass false:
let ias = new InfiniteAjaxScroll(/*..*/, {
logger: false
})
Configures if the next/previous page should automatically be loaded when the users scrolls to the bottom or the top of the page.
let ias = new InfiniteAjaxScroll(/*..*/, {
loadOnScroll: false
})
// the hit event is still emitted, allowing to manually load the next page
ias.on('hit', (event) => {
ias.next();
})
prefill
Type:booleanDefault:trueRequired: no
let ias = new InfiniteAjaxScroll(/*..*/, {
prefill: false
})
// load first page
// notice: even with the first page loaded, the content could still be too short. In that case keep calling `next()` until there is scroll bar.
ias.next();
The pagination elements will be restored (element.style.display -> original value) when is called.
See for available values.
By default Infinite Ajax Scroll binds to the scroll and resize events on document ready. If you want to have manual control over this behaviour you can set this option to false. To bind manually you can call the method.
Type:Object|booleanDefault:Object (see )
Required: no
On default events are logged to console (see ):
When loadOnScroll is disabled the event is still emitted, allowing you to manually trigger the next/prev page (for example by calling ).
We can use and to configure this setting on runtime.
When enabled, and the content is shorter than the scroll container, Infinite Ajax Scroll will load the next page(s) until the content is taller than the scroll container. When disabled the responsibility to load the next page is in the hands of the developer. This can be done by calling manually.
We can listen to the and events to act on respectively the start and finish of the prefill action.