我有这个用于加载数据的代码。当用户向下滚动半个屏幕时,它会继续加载数据并将 HTML 附加到文档中。The problem is $(window).height() doesn't update on the fly after HTML changes
所以条件表达式出错了。如何解决?
// Check scrollbar is down a half.
$(window).scroll(function() {
console.log("flag: " + flag);
console.log($(window).scrollTop());
console.log($(window).height());
if (($(window).scrollTop() > $(window).height() / 2)) {
if(flag == 0) {
console.log("Load data");
loadData(globalIndex, globalCount);
globalIndex += 40;
}
flag = 1;
} else {
flag = 0;
}
});