0

有没有人可以解释一下这段jquery代码?我被变量currentnext. 他们实际上在检索什么?

function rotate() { 

//Get the first image

var current = ($('#images .image.show')?  $('#images .image.show') : $('#images .image:first'));
if ( current.length == 0 ) current = $('#images .image:first');
//Get next image, when it reaches the end, rotate it back to the first image

var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#images .image:first') :current.next()) : $('#images .image:first'));
    //Un-comment the 3 lines below to get the images in random order
    //var sibs = current.siblings();
    //var rndNum = Math.floor(Math.random() * sibs.length );
    //var next = $( sibs[ rndNum ] );
    //Set the fade in effect for the next image, the show class has higher z-index

next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
//Hide the current image
current.animate({opacity: 0.0}, 1000).removeClass('show');

};
4

1 回答 1

1

这些是三元或条件运算符

这些相当于:

if($('#images .image.show')){ 
    var current = $('#images .image.show');
}
else{
    var current = $('#images .image:first');
}

if(current.next().length){
    if(current.next().hasClass('show')){
        var next = $('#images .image:first');
    }
    else{
        var next = current.next();
    }
else{
    var next = $('#images .image:first');
}
于 2013-07-07T19:55:44.483 回答