easy-pullrefresh
Version:
A lightweight JS library for pull to refresh
55 lines (42 loc) ⢠1.91 kB
Markdown
# easy-pullrefresh
šÆ A lightweight, dependency-free **pull to refresh library** for mobile web. Supports both **Vue** and **React**, and written in **TypeScript**.
## š Features
- ā
**Tiny & fast**
- ā
**No dependencies**
- ā
**No HTML Layout Requirements**
- ā
**Smooth damping effect**
- ā
**Custom indicator rendering**
- ā
**Supports both Vue & React**
- ā
**Typescript support out-of-the-box**
---
## š¦ Installation
```bash
npm install easy-pullrefresh
```
## āļø Usage
### Basic Example
```ts
import initPullRefresh from 'easy-pullrefresh'
initPullRefresh({
container: document.querySelector('.scroll-container'),
onRefresh: async () => {
await fetchData()
},
indicatorRender: (status) => {
if (status === 'pulling') return '<span style="color: #e8e8e8">ā Pull to refresh...</span>'
if (status === 'loading') return 'š Refreshing...'
return ''
}
})
```
---
## š Options
| Option | Type | Required | Description |
|------------------|-------------------------------|----------|-------------|
| `container` | `HTMLElement` | ā
| Scrollable container |
| `onRefresh` | `() => Promise<void>` | ā
| Called when pull exceeds threshold |
| `indicatorRender`| `(status, distance) => string` | ā |Render function for status indicator. <br> The `status` can be: <br> - `'idle'`: no interaction<br> - `'pulling'`: user is pulling<br> - `'loading'`: refresh in progress. <br> The `distance` is the pull distance |
| `threshold` | `number` | ā | Minimum pull distance to trigger `onRefresh` (default: `60`) |
---
## š” Advanced Tips
* Want to control animation of the indicator on pulling? Use **Lottie**, SVG or sprite frames inside `indicatorRender`.