Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kanety/stimulus-iscroll


https://github.com/kanety/stimulus-iscroll

Last synced: 8 days ago
JSON representation

Awesome Lists containing this project

README

        

# stimulus-iscroll

A stimulus controller for simple infinite scroll.

## Dependencies

* @hotwired/stimulus 3.0+

## Installation

Install from npm:

$ npm install @kanety/stimulus-iscroll --save

## Usage

Register controller:

```javascript
import { Application } from '@hotwired/stimulus';
import IscrollController from '@kanety/stimulus-iscroll';

const application = Application.start();
application.register('iscroll', IscrollController);
```

Build html as follows:

```html





header
header




content
content





index.1.html
index.2.html
index.3.html



```

### Options

#### loading

Show specific element while loading:

```html






```

#### next-link

Set selector to get next link in paging target (default is `a.next`):

```html



```

You can set the selector globally:

```javascript
import IscrollController from '@kanety/stimulus-iscroll';
IscrollController.nextLink = 'a.next';
```

#### margin

Set margin height to start loading before reaching at the bottom of scroll bar:

```html



```

### Callbacks

Run callbacks when next page is loaded:

```javascript
let element = document.querySelector('[data-controller="iscroll"]');
element.addEventListener('iscroll:start', e => {
console.log(e.detail.href);
});
element.addEventListener('iscroll:done', e => {
console.log(e.detail.href);
console.log(e.detail.error.content); // new content element
console.log(e.detail.error.paging); // new paging element
});
element.addEventListener('iscroll:fail', e => {
console.log(e.detail.href);
console.log(e.detail.error.message);
});
element.addEventListener('iscroll:end', e => {
console.log(e.detail.href);
});
```

## License

The library is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).