开发者

need help with jquery selectors

I've got code like that:

<ul class="gallery_demo_unstyled">
    <li class="active"><img src='001.jpg' /></li> 
    <li><img src='002.jpg' /></li> 
    <li><img src='003.jpg' /></li> 
    <li><img src='004.jpg' /></li> 
    <li><img src='005.jpg' /></li> 
    <li><img src='006.jpg' /></li> 
</ul> 

<div class="Paginator"> 
    <a href="../2/" class="Prev">&lt;&lt;</a> 
    <a href="../1/">1</a> 
    <a href="../2/">2</a> 
    <span class="this-page">3</span> 
    <a href="../4/">4</a> 
    <a href=开发者_运维百科"../5/">5</a> 
    <a href="../4/" class="Next">&gt;&gt;</a> 
</div> 

<div class="Albums"><div class="AlbumsMenu">
<p><b>ALBUMS</b></p>
    <p><a href="../../blackandwhite/1/" >blackandwhite</a></p>
    <p><a href="../../color/1/" class='this-page'>>>color</a></p>
    <p><a href="../../film/1/" >film</a></p>
    <p><a href="../../digital/1/" >digital</a></p>
    <p><a href="../../portraits/1/" >portraits</a></p>
</div></div>  

...and some JavaScript/jQuery allowing to cycle through the images (the very top li elements) going back to the first image after the last one:

$$.nextSelector = function(selector) {
return $(selector).is(':last-child') ?
       $(selector).siblings(':first-child') :
       $(selector).next();

};

Current page is always 'this-page' class (span or p in my case, but I could change that if necessary).

The question: what should I change in my code to make it go after the last image to the next page instead of cycling through the page over and over again, and after the last page to the next album? And to the first image on the first page of the first album after the last-last-last (or just stop there — don't really care)?


something like this:

function nextImage()
{
    var li = $('#gallery_demo_unstyled li.active');

    if (li.is(':last-child')) {
        nextPage();
    } else {
        li.removeClass('active');
        li.next().addClass('active');
    }
}

function nextPage()
{
    var next = $('div.Paginator a.Next');

    if (next.length == 0) {
        nextAlbum();
    } else {
        window.location = next.attr('href');
    }
}

function nextAlbum()
{
    var this_album = $('div.AlbumsMenu p a.this-name');
    var p = this_album.parent();

    if (p.next().length == 0) {
        return;
    }

    window.location = p.next().children('a').attr('href');
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜