m-pull-to-refresh icon indicating copy to clipboard operation
m-pull-to-refresh copied to clipboard

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

Open zhengcanbiao opened this issue 6 years ago • 1 comments

亲测部分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; } }

zhengcanbiao avatar Sep 26 '18 07:09 zhengcanbiao

亲测部分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

11341684 avatar Oct 09 '19 02:10 11341684