获得第二个可见的李

时间:2016-12-16 12:24:12

标签: javascript jquery

我有一个导航栏。每个li都可以有一个弹出窗口,这些弹出窗口中的li也可以有弹出窗口。我试图动态限制一次只显示10,并有一个上一个和下一个按钮。

$("#nextButton").live('click', function()
{
    // Get li's in navbar and the size of them
    var list = $(this).siblings();
    var listLength = $(list).length - 1; // -1 because of nav button (siblings doesn't include this)


    // remove hidden elements from list
    $(list).each(function()
    {   var increment = 0;
        increment++;
        if($(this).css("display") == "none")
        {
            list.splice(increment, 1);
        }
    });

    var p = $(list).selector+':nth-last-child(2)'.index(); // I would like get the second last element (this line does not work)
    //below commented out does not work
    //var item = $(list).last().prev().index();
    // Dynamically check if can navigate 10 items back
    var postionIfNext = ($(list).index() + 9); // 9 bcus we manually add the prev btn which = 10
    if(postionIfNext <= listLength)
    {
        $(this).siblings().hide().slice((postionIfNext - 10), postionIfNext).show();
        $(this).siblings().slice(0,1).show(); // show prev btn
    }       
    });

0 个答案:

没有答案