頁面滾動到底部加載更多分頁


 
         
// 通常寫法
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);
})
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM