UNPKG

easy-pullrefresh

Version:

A lightweight JS library for pull to refresh

55 lines (42 loc) • 1.91 kB
# 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`.