Mobile Pull-to-Refresh and Pull-Up Loading Effects Mimicking Native Behavior Based on iScroll5 (Original)

Add-ons
2026-07-26 01:02 6 次浏览 • 0 次下载 18.0KB
Mobile Pull-to-Refresh and Pull-Up Loading Effects Mimicking Native Behavior Based on iScroll5 (Original)

Last updated: 2018/11/22 8:54:58 AM

Changelog:Added a mobile rem adaptation plugin.


Release date: 2018-11-22 0:59

Note: This plugin is designed for mobile development. For the best browsing experience, use a mobile phone or the device simulator in your browser's developer tools.

A recent project used iScroll5, so I tried implementing mobile pull-to-refresh and pull-up loading effects. However, I found that no matter what I did, I couldn't perfectly reproduce the native behavior. After carefully inspecting the code, I discovered that when iScroll5 resets the position, if the current Y coordinate is greater than 0, it always scrolls back to 0 and cannot be dynamically configured. So I briefly examined the source code and modified the following sections.

1. Open the iscroll-probe.js file.

2. Find:

1
2
this.maxScrollX = this.wrapperWidth - this.scrollerWidth;
this.maxScrollY = this.wrapperHeight - this.scrollerHeight;

Change it to:

1
2
3
4
this.minScrollX = 0;
this.minScrollY = 0;
this.maxScrollX = this.wrapperWidth - this.scrollerWidth;
this.maxScrollY = this.wrapperHeight - this.scrollerHeight;

3. Find:

1
2
3
4
5
6
7
8
9
10
if ( !this.hasHorizontalScroll || this.x > 0 ) {
x = 0;
} else if ( this.x < this.maxScrollX ) {
x = this.maxScrollX;
}
if ( !this.hasVerticalScroll || this.y > 0 ) {
y = 0;
} else if ( this.y < this.maxScrollY ) {
y = this.maxScrollY;
}

Change it to:

1
2
3
4
5
6
7
8
9
10
if ( !this.hasHorizontalScroll || this.x > 0 ) {
x = this.minScrollX;
} else if ( this.x < this.maxScrollX ) {
x = this.maxScrollX;
}
if ( !this.hasVerticalScroll || this.y > 0 ) {
y = this.minScrollY;
} else if ( this.y < this.maxScrollY ) {
y = this.maxScrollY;
}

Now, when pulling down, you can dynamically modify the minScrollY property of the instance according to the situation to achieve the desired effect.

星河码客

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

关于本站

联系我们

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

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

Powered by Nuxt · Deployed on Cloudflare