Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zhengcanbiao opened this issue Sep 26, 2018 · 1 comment
Open

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

zhengcanbiao opened this issue Sep 26, 2018 · 1 comment

Comments

@zhengcanbiao
Copy link

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

11341684 commented Oct 9, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants