2013-01-15 187 views
0

我無法弄清楚如何讓這段代碼正常工作。從這個代碼塊意外標識符:Javascript

complete:function() { 

::我recieving爲線意外標識符

$(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所以我可能失去了一些東西很明顯這裏..

回答

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); 
     } 
    } 
); 
+0

謝謝你,我做了一個改變,但仍然正在一個「意外的標記」爲完成:函數(){行 –

+0

在哪個瀏覽器? –

+0

查看我的版本。 –

0

後續的線仍然是錯誤的

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

不能命名參數「時間」和「完整」,正確的路線是

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

注意變量「持續時間」,你也把它放在一個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; 
    } 
+0

這個作品,以及謝謝你 –