Jquery 在无限滚动中选择当前页面的每个功能

Jquery 在无限滚动中选择当前页面的每个功能,jquery,ajax,infinite-scroll,pushstate,Jquery,Ajax,Infinite Scroll,Pushstate,我在一个站点中加入了一点Jquery,当您接近当前页面的底部时,它会加载并附加下一个页面。我想检测用户在页面上的位置,以便使用history.pushstate()修改URL 每个页面都包装在“load part”类中 var load_number; var start_offset; var end_offset; // Run a function on each page $('.load-part').each(function() { // Get the page num

我在一个站点中加入了一点Jquery,当您接近当前页面的底部时,它会加载并附加下一个页面。我想检测用户在页面上的位置,以便使用history.pushstate()修改URL

每个页面都包装在“load part”类中

var load_number;
var start_offset;
var end_offset;
// Run a function on each page
$('.load-part').each(function() {

    // Get the page number 
    load_number = parseInt($(this).attr('id').replace("load-part-",""));

    // Get the true top offset of the page
    start_offset = $(this).children().first().offset().top;

    // Get the true bottom offset of the page
    end_offset = $(this).children().last().offset().top + window_height;

    // If the window is between the limits - i.e. on this page
    if (start_offset <= $(window).scrollTop() < end_offset) {

        // Update the URL with the current page number
        history.pushState(null, null, load_number)
    }
}); 
var负载号;
var起始偏移量;
var端偏移量;
//在每个页面上运行一个函数
$('.load part')。每个(函数(){
//获取页码
load_number=parseInt($(this).attr('id').replace(“加载部分-”,“”);
//获取页面的真实顶部偏移量
start_offset=$(this).children().first().offset().top;
//获取页面的真实底部偏移量
end_offset=$(this).children().last().offset().top+窗高;
//如果窗口在限制之间-即在本页上

if(start_offset
if(start_offset)啊,是的!谢谢。我不完全确定为什么要拆分像这样的if条件?因为我很抱歉地说:这是条件在js中的工作方式,一次一个测试。
if (start_offset <= $(window).scrollTop() && $(window).scrollTop() < end_offset) {

        // Update the URL with the current page number
        history.pushState(null, null, load_number)
    }