简体   繁体   English

需要jquery选择器的帮助

[英]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: ...和一些JavaScript / jQuery允许循环遍历图像(最顶层的li元素)返回到最后一个图像之后的第一个图像:

$$.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). 当前页面始终是“此页面”类(在我的情况下为span或p,但如果需要,我可以更改它)。

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');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM