带侧边栏导航的无限滚动

时间:2011-11-18 01:52:33

标签: javascript jquery

我正在通过Ajax加载结果。我正在使用无限滚动来分页结果。 当新内容加载时,我有一个漂亮的小侧边栏跟随页面。

我现在面临的问题是,漂亮的侧边栏上有字母A-Z。当用户点击其中一个字母时,我需要取消绑定滚动事件 - >从最后一个部分创建占位符,直到下一个请求部分(A-Z) - >加载请求的部分,然后继续重新绑定$(窗口).scroll()。它实际上(或应该工作)与Facebook的时间轴紧密相关。

我不能为我的生活弄清楚当你点击侧边栏时如何取消绑定滚动事件。我已经删除了固定的侧边栏代码和数据检索,因为它在这里没有用处。

一些代码......

// i use this array to figure out which section of data i need next
var letters = new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');

// get the default set of data to display BEFORE scroll
// -> some code...

// remove letter from array
letters.splice(0, 1);

// scroll
$(window).scroll(function(event){
var doc_height          = parseInt($(document).height()),
    window_height       = parseInt($(window).height()),
    scroll_at_height    = parseFloat(doc_height - parseFloat(doc_height / 10) - window_height),
    scroll_y            = $(window).scrollTop();

// check if the scroll height is met and pull next recordset
if (scroll_y >= scroll_at_height) {

    // as long as there are still more sections to go [var letters]
    if (letters.length > 0) {

        // get next set
        // -> some code to get the next set of data...

        // remove letter from [letters] array
        letters.splice(0, 1);
    }
}
});

// sidebar nav
$('.letter-picker a').bind('click', function() {
// nothing here works anywho...

return false;
});

0 个答案:

没有答案
相关问题