我试图在用户向下滚动并到达页面底部时触发事件。检查用户是否已到达页面底部
我搜索了互联网,发现了一些帖子在stackoverflow但意外的答案没有为我工作。
例:Check if a user has scrolled to the bottom
使用上述SO后给出的答案,到达页面的顶部而不是底部时,执行我试图触发事件。
请让我知道,如果我错了:
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
loadmore();
}
});
function loadmore(){
var lastProd = $('.product_div').last();
var lastProdID = $('.product_div').last().prop('id');
//console.info(lastProdID); return false;
//var val = document.getElementById("row_no").value;
$.ajax({
type: 'post',
url: 'includes/load_products.php',
data: { getresult:lastProdID },
success: function (response) {
console.log(response);
//var content = document.getElementById("all_rows");
//content.innerHTML = content.innerHTML+response;
lastProd.after(response);
// We increase the value by 10 because we limit the results by 10
// document.getElementById("row_no").value = Number(val)+10;
}
});
}
是否有在控制台中的任何错误?如果没有可重复的东西,这将很难帮助你。 – Script47
你可以用你现在的代码创建一个JSFiddle吗? –
好的,我会创建一个jsfiddle – goseo