意外标识符:Javascript

意外标识符:Javascript,javascript,identifier,Javascript,Identifier,我不知道如何让这段代码正常工作。我收到该行的意外标识符: complete:function() { $("#rightdoor,#leftdoor").animate({"marginLeft":"0px"}{duration:duration,complete:function() { 从这段代码中: $(document).ready(function(){ var doorOpen = false; $("a[href=#andrew]").click(function() {

我不知道如何让这段代码正常工作。我收到该行的意外标识符:

complete:function() {
$("#rightdoor,#leftdoor").animate({"marginLeft":"0px"}{duration:duration,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新手,所以我可能在这里遗漏了一些明显的东西。

请看这行:

complete:function() {
$("#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);
        }
    }
);

跟随的路线仍然是错误的

$("#rightdoor,#leftdoor").animate({"marginLeft":"0px"}      duration:duration,complete:function() {
不能将参数命名为“duration”和“complete”,正确的行是

$("#rightdoor,#leftdoor").animate({"marginLeft":"0px"}, duration, function() {
也要注意变量“duration”,你把它放在了一个if块中,变量 如果在“动画”行中未定义,则可以更改“持续时间”的声明,如下所示:

$("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;
    }

谢谢,我确实做了更改,但仍然得到了完整的:function()的“意外标记”{line