react-component / m-pull-to-refresh

React Mobile Pull To Refresh
http://react-component.github.io/m-pull-to-refresh/
163 stars 61 forks source link

isEdge对部分安卓机判断不生效 #23

Open zhengcanbiao opened 6 years ago

zhengcanbiao commented 6 years ago

亲测部分android机型拖动多次会拖动不了,因为 ele.scrollHeight - ele.scrollTop === ele.clientHeight + 1,所以一直判断不为edge,上拉刷新不了,所以isEdge方法可以加一行代码兼容一下。 机型为:oppo A57

修改isEdge函数 isEdge(ele, direction) { const container = this.props.getScrollContainer(); // 父容器需要设置height100vh,scroll auto时,scrollTop才会改变,不然一直为0 if (container && container === document.body) { // In chrome61 document.body.scrollTop is invalid const scrollNode = document.scrollingElement ? document.scrollingElement : document.body; if (direction === UP) { return scrollNode.scrollHeight - scrollNode.scrollTop <= window.innerHeight; } if (direction === DOWN) { return scrollNode.scrollTop <= 0; } } if (direction === UP) { // 兼容部分android机型,需要 + 1px return ele.scrollHeight - ele.scrollTop === ele.clientHeight + 1 || ele.scrollHeight - ele.scrollTop === ele.clientHeight; } if (direction === DOWN) { return ele.scrollTop <= 0; } }

11341684 commented 5 years ago

亲测部分android机型拖动多次会拖动不了,因为 ele.scrollHeight - ele.scrollTop === ele.clientHeight + 1,所以一直判断不为edge,上拉刷新不了,所以isEdge方法可以加一行代码兼容一下。 机型为:oppo A57

修改isEdge函数 isEdge(ele, direction) { const container = this.props.getScrollContainer(); // 父容器需要设置height100vh,scroll auto时,scrollTop才会改变,不然一直为0 if (container && container === document.body) { // In chrome61 document.body.scrollTop is invalid const scrollNode = document.scrollingElement ? document.scrollingElement : document.body; if (direction === UP) { return scrollNode.scrollHeight - scrollNode.scrollTop <= window.innerHeight; } if (direction === DOWN) { return scrollNode.scrollTop <= 0; } } if (direction === UP) { // 兼容部分android机型,需要 + 1px return ele.scrollHeight - ele.scrollTop === ele.clientHeight + 1 || ele.scrollHeight - ele.scrollTop === ele.clientHeight; } if (direction === DOWN) { return ele.scrollTop <= 0; } }

设置误差范围靠谱点,这玩意有时候返回的是小数,Math.abs(ele.scrollHeight - ele.scrollTop - ele.clientHeight)<=1