带有if else语句的WP循环

时间:2013-06-24 18:12:33

标签: jquery wordpress if-statement

我正在使用WP滑块,并希望根据滑块循环中的div数使用不同的动画。下面是我到目前为止,只有一个if语句可以正常工作,但我想使用多个if语句。

有人可以帮忙吗?提前感谢您寻找:)

jQuery(document).ready(function(){ 

var tl = new TimelineMax({repeat:-1}),

        slide1 = document.getElementById("slide1"),
        head1 = document.getElementById("head1"),
        sub1 = document.getElementById("sub1"),
        p1 = document.getElementById("p1"),

        slide2 = document.getElementById("slide2"),
        head2 = document.getElementById("head2"),
        sub2 = document.getElementById("sub2"),
        p2 = document.getElementById("p2"),

 n = jQuery("#slider div").length;

 if (n == 2) {
    tl.to(slide1, 1, {left:0 }, "slide10end")
    .from(head1, 1, {left:-1000}).to(head1, 1, {top:50}).to(head1, 1, {top:50}).to(head1, 1, {opacity:0})
    .to(sub1, 1, {right:-200}).to(sub1, 1, {rotation: 720}).to(sub1, 1, {opacity:0})
    .from(p1, 1, {scale:0}).to(p1, 1, {scale:1}).to(p1, 1, {scale:0})
    .to(slide1, 1, {left:-2000 }, "slide1end")

} 
else if (n == 3) {

    tl.to(slide1, 1, {left:0 }, "slide10end")
    .from(head1, 1, {left:-1000}).to(head1, 1, {top:50}).to(head1, 1, {top:50}).to(head1, 1, {opacity:0})
    .to(sub1, 1, {right:-200}).to(sub1, 1, {rotation: 720}).to(sub1, 1, {opacity:0})
    .from(p1, 1, {scale:0}).to(p1, 1, {scale:1}).to(p1, 1, {scale:0})
    .to(slide1, 1, {left:-2000 }, "slide1end")

    .to(slide2, 1, {left:0 })
    .from(head2, 1, {left:-1000}).to(head2, 1, {left:-1000, delay:1})
    .to(sub2, 1, {right:-200}).to(sub2, 1, {right:-2000, delay:1, opacity:0}).to(sub2, 3, {right:-2000}, "-=0.9")
    .from(p2, 1, {left:-2000, ease:Bounce.easeOut}).to(p2, 1, {opacity:0, delay:1})
    .to(slide2, 1, {left:-2000 }, "slide2end")


} 

else (n == 4) {


    //slider 3
    tl.to(slide3, 1, {left:0 })
    .from(head3, 1, {left:-1000}).to(head3, 1, {left:-1000, delay:1})
    .to(sub3, 1, {right:-200}).to(sub3, 1, {right:-2000, delay:1, opacity:0}).to(sub3, 3, {right:-2000}, "-=0.9")
    .from(p3, 1, {left:-2000, ease:Bounce.easeOut}).to(p3, 1, {opacity:0, delay:1})
    .to(slide3, 1, {left:-2000 }, "slide2end")
} 

});

1 个答案:

答案 0 :(得分:0)

您在上次比较时遇到语法错误:} else (n == 4) {不是有效结构。要么使用其他if,要么删除括号,其余为} else {