diff --git a/docs/advanced/triggers.md b/docs/advanced/triggers.md index c79dd633..99825b92 100644 --- a/docs/advanced/triggers.md +++ b/docs/advanced/triggers.md @@ -1,9 +1,5 @@ # Triggers -{% hint style='working' %} -This feature is still work in progress -{% endhint %} - Instead of loading next pages on scroll you can use a trigger. A trigger is a link or button that has to be clicked before the next page is loaded. Reasons for a trigger might be: @@ -11,3 +7,49 @@ Reasons for a trigger might be: * To make the footer reachable. * To ease the load on the server. Users have to click before loading the next page. This adds a natural delay. +First add a button to your document + +```html + +``` + +Next add a bit of CSS to make it look nice and hide if from view (opacity 0) + +```css +.load-more { + display: inline-block; + height: 32px; + padding: 0 16px; + border: 1px solid #aaa; + border-radius: 4px; + opacity: 0; + font-family: Lucida Grande,Lucida Sans Unicode,Lucida Sans,Geneva,Arial,sans-serif; + font-size: 14px; + font-weight: 400; + line-height: 30px; + color: #555; + background-color: #fff; + cursor: pointer; + transition: opacity .4s; +} + +.load-more:hover { + color: #F63840; + border: solid 1px #F63840; +} +``` + +Next configure the trigger. + +```javascript +let ias = new InfiniteAjaxScroll(/*..*/, { + // other options here + + trigger: '.load-more' +}); +``` + +See [trigger options](../options.md#trigger) for information. + +[View this behaviour in a live demo](https://infiniteajaxscroll.com/examples/button/) + diff --git a/docs/options.md b/docs/options.md index 810979dc..dfdd6f46 100644 --- a/docs/options.md +++ b/docs/options.md @@ -176,17 +176,20 @@ You can also set advanced spinner options. ```javascript let ias = new InfiniteAjaxScroll(/*..*/, { spinner: { - // element + // 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 @@ -217,6 +220,16 @@ let ias = new InfiniteAjaxScroll(/*..*/, { // 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; + }, }) ``` @@ -225,16 +238,19 @@ We can also set advanced trigger options. ```javascript let ias = new InfiniteAjaxScroll(/*..*/, { trigger: { - // element + // 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 diff --git a/examples/button/index.html b/examples/button/index.html index 5fd5109c..f37341ef 100644 --- a/examples/button/index.html +++ b/examples/button/index.html @@ -16,7 +16,7 @@