页面滚动到底部加载更多分页


// 通常写法
window.onscroll = function (e) { /* 判断是否滚到最下面 */ /* 如果已经滚到最下面则执行某个操作 */ var e =e || window.event; // 为了兼容谷歌和火狐 document.body.scrollTop是谷歌上的 /* 滚动条的垂直位置 */ var scrolltop = document.documentElement.scrollTop||document.body.scrollTop; /* 整个页面的正文高度 */ var scrollHeight = document.documentElement.scrollHeight||document.body.scrollHeight; /* 可见区域高度 */ var clientHeight = document.documentElement.clientHeight||document.body.clientHeight; /* 当scrolltop加clientHeight 等于scrollHeight */ if(scrollHeight === (scrolltop+clientHeight)){ loadmore(); } }

// 特定区域元素
handleScroll() {
// -160 去掉非可视List内容区高度 var scrollTop = this.answerRef.scrollTop; // 滚动条溢出高度 var windowHeight = (document.documentElement.clientHeight - 160) || (document.body.clientHeight - 160); // 可视窗口高度 var scrollHeight = this.answerRef.scrollHeight; // 滚动内容高度 // console.log(scrollTop, windowHeight, scrollHeight) if (scrollTop + windowHeight == scrollHeight) {this.pageInfo.pageNum++; return false; } },

this.$nextTick(() => {
this.answerRef = this.$refs.answer;
window.addEventListener("scroll", this.handleScroll, true);
})
 
原文地址:https://www.cnblogs.com/jiaqi1719/p/13728153.html