我试图在我的 div 中创建一个动态滚动,在我到达 div 的底部之前,数据可以继续加载。我耳朵后面湿透了,不确定我是否以正确的方式看待这个问题,因为我的代码根本没有触发。任何指导将不胜感激
function yHandler (){
var movelist = document.getElementById('movelist');
//turning div into an object
var contentHeight = movelist.offsetHeight;
//gets page content height, this so you know how much vetical pixel height you
//have on the page
var yOffset = movelist.pageYoffset;
//get vertical scroll position, lets you know where the user is in their scroll
//postion
var y = yOffset + movelist.innerHeight;
//getting inner height of div
if(y >= contentHeight){
//if the user scrolls to the bottom. If user goes over or hits it
movelist.innerHTML += '<div class ="newData">hey look at me</div>';
}
}
div.onscroll = yHandler;
//监听并在 div 向上或向下滚动时触发 yHandler