首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jquery代码解释

问jquery代码解释
EN

Stack Overflow用户
提问于 2013-07-08 03:50:18
回答 1查看 116关注 0票数 0

有没有人能给我解释一下这段jquery代码?我被变量current和next卡住了。他们实际检索的是什么?

代码语言:javascript
复制
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');

};
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-08 03:55:44

这些是ternary or conditional operators

它们等同于:

代码语言:javascript
复制
if($('#images .image.show')){ 
    var current = $('#images .image.show');
}
else{
    var current = $('#images .image:first');
}

和

代码语言:javascript
复制
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');
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17515695

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档