上拉加载更多的js代码用的和网上的都一样
$(window).scroll(function(){
var scrollTop = $(this).scrollTop();
var scrollHeight = $(document).height();
var windowHeight = $(this).height();
console.log(scrollTop+"--"+windowHeight+"--"+scrollHeight);
if(scrollTop + windowHeight == scrollHeight){
//ajax请求
}
});
但是在上拉到底部时,就是不触发。console的结果显示scrollTop的值正常变化,而windowHeight和scrollHeight的值竟然一直都是相同的,所以才不能触发。经过老长时间的折腾才发现,是因为html头部没有加
<!DOCTYPE html>
这句话造成的,真是坑啊,这谁能想到这玩意。在这里记一下,留着用