Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dblate/scroll-loader
抽象出“滑动加载更多”的解决方法
https://github.com/dblate/scroll-loader
Last synced: about 1 month ago
JSON representation
抽象出“滑动加载更多”的解决方法
- Host: GitHub
- URL: https://github.com/dblate/scroll-loader
- Owner: dblate
- Created: 2018-06-06T12:09:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-06-06T12:21:28.000Z (over 6 years ago)
- Last Synced: 2024-10-09T19:39:42.028Z (about 1 month ago)
- Size: 1000 Bytes
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# scroll loader
对“滑动加载更多”的处理方法的抽象,用流行点的术语来说,算是 HOC(high order component)
## 使用
```javascript
import ScrollLoader from 'scroll-loader';const el = document.getElementById('el-to-listen');
const scrollloader = new ScrollLoader();
// 当 el 元素滑动到屏幕底部时,执行 updateCnt
scrollloader.addListener(el, updateCnt);// 如果涉及异步操作,那么应该返回 promise,因为在执行该函数后, scroll-loader 还有事做
function updateCnt(page) {
return new Promise((resolve, reject) => {
$.ajax({
url: '',
data: {},
success() {
// do someting here..resolve();
},
error() {
reject();
}
})
});
}```