Reputation: 287
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..
Upvotes: 0
Views: 2326
Reputation: 968
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;
}
Upvotes: 0
Reputation: 25682
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);
}
}
);
Upvotes: 1