用户到达底部时如何加载新页面/URL
问题描述:
我正在创建无限负载,这意味着当用户到达页面/特定div的底部时,将加载一个新页面. 目前,我有此代码可以在点击时加载新页面.
I am creating infinite load,means a new page gets loaded when user reach bottom of the page/particular div. Currently i have this code to load new page on click.
$("#about").click(function(){
// load about page on click
$("#response").load("about.html");
});
这里的任何人对如何在不单击/到达底部的情况下加载新页面有更清晰的认识
Does anyone here have more clear idea of how to load new page without click/reaching a bottom
答
您可以根据鼠标窗口位置发送ajax调用.
You can send the ajax call based on mouse window position.
var no=1;
$(window).scroll(function () {
if(no==1)
{
if ($(window).height() + $(window).scrollTop() == $(document).height()) {
no=2;
$.ajax({
type: "POST",
url: "about.html",
data: datas,
cache: false,
success: function(html){
}
});
}
}
});
此ajax调用将在用户到达页面末尾时调用.您可以指定它发生的高度.
This ajax call will call when a user reaches at end of page. You can specify a height at which it occurs.