0

我尝试在每次点击时增加一次,但是我坚持使用这个原始代码:

$('.de img').click(function() {
            scroll = $('body').scrollTop();
            imgJump = $(this).prevAll().length;
        var $this = $(this),
            bigImgs = $('.biggie:hidden').find('img:hidden');
            console.log(bigImgs[imgJump]);
        $('.de').fadeOut(400, function () {
                $('body').scrollTop(0);
                $('.biggie').fadeIn(400);
            });

        $(bigImgs[imgJump]).fadeIn(400);
        $('.biggietext').fadeIn(400);
        $('.number').text(imgJump + 1);
}); 

$('.biggie img').click(function(){
    var imgIs = imgJump + 1,
        imgIss = imgIs++;

    if ($(this).nextAll().length > 0) {
        $(this).fadeOut(400, function() {
            $(this).next().fadeIn(400);
        });
        $('.number').text(imgIss);                  
        }
});

这是一个更简单版本的 jsFiddle:http: //jsfiddle.net/nU63B/3/

为什么这不起作用?

谢谢!!

4

1 回答 1

1

它不会增加,因为你if satement没有被执行

if ($(this).nextAll().length > 0) { // $(this).nextAll().length 
                                    //returns 0 and hence not working

您只有一个元素(p标签),并且没有与之关联的兄弟姐妹,因此它的长度返回 0。

nextAll()获取匹配元素集中每个元素的所有后续兄弟,可选地由选择器过滤。

将其更改为

if ($(this).nextAll().length == 0) { 

工作小提琴

于 2013-11-05T08:32:55.310 回答