2014-10-04 55 views
0

我已经将一点点的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) 
    } 
}); 

我得到的问题是,if语句似乎是真实的评估不论,即使window.scrollTop()值显然不限制之间下降。我究竟做错了什么??

回答

0
if (start_offset <= $(window).scrollTop() && $(window).scrollTop() < end_offset) { 

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

更多的东西支持JavaScript的

+0

是啊!谢谢。如果条件如此,我不完全确定你为什么要分手? – Jacob 2014-10-04 11:07:42

+0

因为我很抱歉地说:这是条件在js中的工作方式,一次只能进行一次测试。 – 2014-10-04 12:09:21