scrollHeight:文檔內(nèi)容實際高度灸拍,包括超過屏幕視口高度溢出的部分做祝。=內(nèi)容的大小+paddng
scrollTop:滾動條距元素(不一定是屏幕最頂端)頂部滾動的距離。
clientHeight:瀏覽器窗口可視范圍高度(就是自己能看到的高度鸡岗,如果這個盒子都在可視區(qū)混槐,內(nèi)容則是盒子的高度)。=元素的大小+padding轩性。
offsetParent:距離該子元素最近的進行過定位的父元素(position:absolute relative fixed)声登,如果其父元素中不存在定位則offsetParent為--body元素。=元素的大小+padding+border
客戶區(qū)大小
滾動偏移
滾動條是否滾到底部的判斷條件是
scrollHeight = scrollTop + clientHeight
所以在實現(xiàn)時我們只要獲取這三個值就可以了揣苏,而這三個值js都有對應(yīng)的api獲取捌刮,分別是
let scrollHeight = document.body.scrollHeight || document.documentElement.scrollHeight
let scrollTop = document.body.scrollTop || document.documentElement.scrollTop
let clientHeight = document.body.clientHeight || document.documentElement.clientHeight
====================================================================================
h5頁面上下滑動翻頁
判斷條件:1)觸底,觸發(fā)翻頁舒岸,2)翻頁的時候绅作,把上一頁內(nèi)容保存一下,下一頁拼接到上一頁內(nèi)容后面蛾派,這樣可以上下翻俄认。
mounted(){
window.addEventListener('scroll', this.handleScroll,true) // 監(jiān)聽頁面滾動*/
},
methods:{
handleScroll () {
//變量scrollTop是滾動條滾動時,距離頂部的距離
let scrollTop = document.documentElement.scrollTop||document.body.scrollTop;
//變量windowHeight是可視區(qū)的高度
let windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
//變量scrollHeight是滾動條的總高度
let scrollHeight = document.documentElement.scrollHeight||document.body.scrollHeight;
let dataArr = []
//滾動條到底部的條件
if(scrollTop + windowHeight === scrollHeight){
dataArr = this.giftList //把上一頁的數(shù)據(jù)賦給dataArr
this.pageNum = this.pageNum + 1
this.getList()//請求到新一頁的數(shù)據(jù)
this.giftList = dataArr.concat(this.giftList)//數(shù)據(jù)拼接
}
},
// 獲取所有展示的兌好禮列表,服務(wù)端接口用 rpc
getList(){
let param = {}
接口(param,function(res){
let res = this.response(res)
this.giftList = res.list
})
},
}
====================================================================================