mescroll Pull-to-Refresh and Infinite Scroll JavaScript Framework

Add-ons
2026-07-26 00:45 5 次浏览 • 0 次下载 1.0KB
mescroll Pull-to-Refresh and Infinite Scroll JavaScript Framework

Usage

1. Download and include the files mescroll.min.css , mescroll.min.js

2. Copy the following layout structure:

1
2
3
<div id="mescroll" class="mescroll"> // The ID can be changed, but the "mescroll" class must not be removed
// List content, for example: <ul>List data</ul> ...
</div>

3. Create a mescroll instance:

1
2
3
4
5
6
7
8
9
10
var mescroll = new MeScroll("mescroll", { // The first parameter "mescroll" corresponds to the ID of the div in the layout structure above
// If your pull-to-refresh operation resets the list data, you do not need to configure down at all. Refer to the first basic example for detailed usage.
// Explanation: down.callback calls mescroll.resetUpScroll() by default. resetUpScroll sets page.num=1 and then triggers up.callback.
down: {
callback: downCallback // Pull-to-refresh callback. Do not write it as downCallback(), because the extra parentheses will execute the method immediately.
},
up: {
callback: upCallback // Infinite scroll callback
}
});

4. Handle callbacks:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Pull-to-refresh callback
function downCallback() {
$.ajax({
url: 'xxxxxx',
success: function(data) {
// Callback for successful network requests. Hide the pull-to-refresh status.
mescroll.endSuccess(); // No parameters
// Set data
// setXxxx(data); // Implement this yourself TODO
},
error: function(data) {
// Callback for failed network requests. Hide the pull-to-refresh status.
mescroll.endErr();
}
});
}
// Infinite scroll callback. page = {num:1, size:10}; num: current page, starting from 1 by default; size: number of items per page, 10 by default.
function upCallback(page) {
$.ajax({
url: 'xxxxxx?num=' + page.num + "&size=" + page.size, // How to change page.num to start from 0?
success: function(data) {
// Callback for successful network requests. Hide both pull-to-refresh and infinite scroll statuses.
// Parameter data.length: total number of items on the current page.
// mescroll automatically checks data.length. If the list contains no data, it displays the empty state configured in empty.
// If there is no data on the next page, it displays a "No more data" message (pay attention to the noMoreSize configuration).
// If you need to force the "No more data" message to appear, call mescroll.endSuccess(0). Pay attention to the noMoreSize configuration.
// If data.length is not passed, only the pull-to-refresh status will be hidden.
mescroll.endSuccess(data.length);
// Set list data
// setListData(data); // Implement this yourself TODO
},
error: function(e) {
// Callback for failed network requests. Hide both pull-to-refresh and infinite scroll statuses.
mescroll.endErr();
}
});
}
星河码客

发现和分享优质开源项目,传承互联网精神,为开发者服务。

关于本站

联系我们

微信/广告合作:ITcloub (备注星河码客)

免责声明:本站资源版权归原作者所有,仅供学习与交流。如有侵权,请通过「关于我们 - 侵权投诉」联系删除。

Powered by Nuxt · Deployed on Cloudflare