因为项目需要,最近使用了iScroll5,但是发现无论如何都不能完美的实现下拉刷新效果。仔细检查了下,发现iScroll5中当重置位置的时候,如果当前Y坐标大于0,则固定滚动回0,无法动态设置。
那么我们只需要进行一点简单的修改,就可以搞定这个问题。
1.找到下面这个部分:
this.maxScrollX = this.wrapperWidth - this.scrollerWidth;
this.maxScrollY = this.wrapperHeight - this.scrollerHeight;
更改为:
this.minScrollX = 0;
this.minScrollY = 0;
this.maxScrollX = this.wrapperWidth - this.scrollerWidth;
this.maxScrollY = this.wrapperHeight - this.scrollerHeight;
2.再找到resetPosition
,将其中:
将: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; }
修改为:
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; }