上拉加载更多组件

封装了一个上拉刷新的组件和大家分享一下。

const toReachBottom = {isBottom: false,scroll: function (callback) {let timer = null;callback && window.addEventListener("scroll", scroll.bind(this));function scroll() {if (timer) {clearTimeout(timer)}timer = setTimeout(() => {//滚动条滚动高度const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;//页面高度const scrollHeight = document.documentElement.scrollHeight;//视图窗口高度const clientHeight = document.documentElement.clientHeight || document.body.clientHeight || window.innerHeight;if (!this.isBottom && scrollTop + clientHeight > scrollHeight - 10) {callback()window.scrollTo(0, scrollTop - 50)}}, 1500)}},isEnd: function () {this.isBottom = true;}
}module.exports = toReachBottom;


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部