0

I cannot figure out how to get this code to work properly. I am recieving an unexpected identifier for the line:

complete:function() {

from this block of code:

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

});

I am new to Javascript so I may be missing something obvious here..

2 Answers 2

1

Look at the line:

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

You're missing a comma between the first two parameters of animate.

It should be:

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

It's better to correct the extra commas which are after the last key-value pair of the objects. It'll save you from errors in IE.

You should change the animate call to:

$("#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);
        }
    }
);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I did make that change but still am getting an "unexpected token" for the complete:function() { line
0

The follow line is still wrong

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

You can't name the parameters "duration" and "complete", the correct line is

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

Pay attention on the variable "duration" too, you did put it in a if block, the variable is undefined at the "animation" line, you may change the declaration of "duration", like this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.