0

我无法弄清楚如何让这段代码正常工作。我收到了该行的意外标识符:

complete:function() {

从此代码块:

$(document).ready(function(){

var doorOpen = false;

$("a[href=#andrew]").click(function() {

    if (doorOpen) { // set animation duration for door close, based on actually needed to animate the door closed or not
        var duration = 1500;
    } else {
        var duration = 0;
    }

    $("#rightdoor,#leftdoor").animate(
        {"marginLeft":"0px"},
        {duration:duration},
            complete:function() {
                $('.pic2 .pic3 .pic4 .pic5').css('zIndex', 1);  //puts wrong pics in back
                $('.pic1').css('zIndex', 2);  //brings right pic into view
                $('#rightdoor').animate({  //opens doors again
                 marginLeft: "150px",
                }, 1500);
                $('#leftdoor').animate({
                 marginLeft: "-150px",
                }, 1500);
            }
    );

    doorOpen = true;

    return false;
});

});

我是 Javascript 新手,所以我可能在这里遗漏了一些明显的东西..

4

2 回答 2

1

看线:

$("#rightdoor,#leftdoor").animate({"marginLeft":"0px"}{duration:duration,complete:function() {

您在动画的前两个参数之间缺少逗号。

它应该是:

$("#rightdoor,#leftdoor").animate({"marginLeft":"0px"},{duration:duration},complete:function() {

最好更正对象的最后一个键值对之后的多余逗号。它将使您免于 IE 中的错误。

您应该将动画调用更改为:

$("#rightdoor,#leftdoor").animate(
    {"marginLeft":"0px"},
    {duration:duration,
        complete:function() {
            $('.pic2 .pic3 .pic4 .pic5').css('zIndex', 1);  //puts wrong pics in back
            $('.pic1').css('zIndex', 2);  //brings right pic into view
            $('#rightdoor').animate({  //opens doors again
             marginLeft: "150px",
            }, 1500);
            $('#leftdoor').animate({
             marginLeft: "-150px",
            }, 1500);
        }
    }
);
于 2013-01-15T17:05:24.697 回答
0

跟随线仍然是错误的

$("#rightdoor,#leftdoor").animate({"marginLeft":"0px"}      duration:duration,complete:function() {

您不能将参数命名为“duration”和“complete”,正确的行是

$("#rightdoor,#leftdoor").animate({"marginLeft":"0px"}, duration, function() {

还要注意变量“duration”,你确实把它放在了一个 if 块中,变量在“animation”行是未定义的,你可以改变“duration”的声明,像这样:

$("a[href=#andrew]").click(function() {

    var duration = 0;
    if (doorOpen) { // set animation duration for door close, based on actually needed to animate the door closed or not
        duration = 1500;
    }
于 2013-01-15T17:54:08.437 回答