1

我有这个:

if(currentSlide !== 3) {
    $('#chapterBackground.intro').fadeOut(100);
}

if(currentSlide !== 4) {
    $('#chapterBackground.intro').fadeOut(100);
}

...并且想从本质上说如果 currentSlide 既不是 3 也不是 4,那么执行 fadeOut 函数。

4

6 回答 6

3
if((currentSlide !== 3) || (currentSlide !== 4))  {
    $('#chapterBackground.intro').fadeOut(100);
}

抱歉,已编辑。

于 2013-08-15T14:33:54.203 回答
2

您可以在单个条件中使用OR运算符:if

if(currentSlide !==3 || currentSlide !==4) {
    $('#chapterBackground.intro').fadeOut(100);
}
于 2013-08-15T14:34:04.670 回答
2

干得好:

if(currentSlide !== 3 || currentSlide !== 4) {
    $('#chapterBackground.intro').fadeOut(100);
}

意思是“||或”。对于“AND”,您将使用&&运算符;)

于 2013-08-15T14:35:33.580 回答
1
if(currentSlide !== 3 || currentSlide !== 4) {
    $('#chapterBackground.intro').fadeOut(100);
}
于 2013-08-15T14:34:34.907 回答
0

这是我的:

if ( currentSlide + 1 >> 1 != 1 )

:D

于 2013-08-15T14:38:31.433 回答
0

只是众多选项之一:

currentSlide = 3;

//The number would match the slide you want the transition to occur at
//So at slide 3 I want the intro to fade out
var slideIndexes = {
        3 : function() { $('#chapterBackground.intro').fadeOut(100); },
        16 : function() { $('#chapterBackground.presentation').fadeOut(100); },
        20 : function () { $('#chapterBackground.credits').fadeOut(100); }
};

if (slideIndexes[currentSlide]) slideIndexes[currentSlide]();

还有一个漂亮的jsfiddle伴随着这段代码。

于 2013-08-15T14:48:00.293 回答