I'm checking if an element is visible at the bottom of the page to apply auto pagination with scroll.
(我正在检查元素是否在页面底部可见,以通过滚动应用自动分页。)
It works fine and ajax gets fired but I keep getting this in the log(它工作正常,ajax被解雇,但我一直在日志中获取)
allNews:418 Uncaught TypeError: Cannot read property 'top' of undefined
at isScrolledIntoView (allNews:418)
Here's the code and note that img#loader is not visible by default for sure
(这是代码,请注意,确保默认情况下img#loader不可见)
<script>
$(document).ready(function() {
$(window).scroll(function () {
if (isScrolledIntoView("img#loader")) {
var cur_page = parseInt($("#cur_page").text());
var last_page = parseInt($("#last_page").text());
$("img#loader").remove();
if (cur_page < last_page) {
$(".blog_loading").css('display','block');
cur_page++;
$("#cur_page").text(cur_page);
$.ajax({
type: 'GET',
url: '/newsPaginate/<?=$lang?>/' + cur_page,
success: function (response) {
//getting data and append it here
$("#bottomLinks").append('<img id="loader" src="/images/loader.svg" style="visibility: hidden; display: block">');
$(".blog_loading").css('display','none');
}
});
}
}
else {
//console.log('no');
}
});
});
function isScrolledIntoView(elem)
{
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top;
return ((elemTop <= docViewBottom) && (elemTop >= docViewTop));
}
</script>
How to fix this to stop logging this to the console
(如何修复此问题以停止将其记录到控制台)
ask by PHP User translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…