データをロードするためのこのコードがあります。ユーザーが画面の半分を下にスクロールすると、データの読み込みとドキュメントへの 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;
}
});