- scrollTop:一個元素的內(nèi)容垂直滾動的高度;
- scrollHeight :一個元素在不使用滾動條的情況下為了適應(yīng)視口中所用內(nèi)容所需的最小高度,包含內(nèi)邊距(padding),不包含外邊距(margin)、邊框(border);
-
clientHeight :返回一個元素的像素高度,高度包含內(nèi)邊距(padding),不包含邊框(border)、外邊距(margin)和滾動條
image.png
監(jiān)聽dom滾動條是否滾動到底部代碼如下:
templatesContainer.addEventListener("scroll", () => {
const domClientHeihgt = templatesContainer.clientHeight;
const domScrollTop = templatesContainer.scrollTop;
const domScrollHeight = templatesContainer.scrollHeight;
if (domScrollTop + domClientHeihgt >= domScrollHeight) {
console.log("滾動到底部");
}
});
