2011-12-05 119 views
0

我需要在內部div淡出之後使'content'div生動。儘管我添加了回調,但fadeOut動畫仍然有效。有人能告訴我在回調函數中搞砸了什麼嗎?jquery回調問題

<script type = 'text/javascript'> 
$(document).ready(function() { 
    $('#content').click(function() { 
     $('#topcontent,#bottomcontent').fadeOut(400, function() { 
      $('#content').css({ 
       position:'relative', 
       background-color:'black' 
      }).animate({ 
       height:$(window).height(), 
       width:$(this).width() 
      },400); 
     }); 
    }); 
}); 
</script> 
</head> 
<body> 
    <div id = 'wrapper'> 
     <div id = 'content'> 
      <div id = 'topcontent'> 
      TOP<br /> 
      </div> 
      <div id = 'bottomcontent'> 
      BOTTOM 
      </div> 
     </div> 
    </div> 
</body> 

回答

2

你的問題是在的.css()調用... background-color:'black'應該background: 'black'

或指出在註釋 「背景色」: '黑'

+0

http://jsfiddle.net/3MCbe/ – biziclop

+1

或'「背景顏色」:「黑」' - 它在導致一個不帶引號鍵連字符語法錯誤。 – nrabinowitz

+1

它應該可能是'backgroundColor',而不僅僅是'background',因爲這是問題中使用的屬性。 –

3
$('#content').css({ 
    position:'relative', 
    'background-color':'black' 
}) 

-字符是JS中減法運算符,在這裏是無效的(即使你試圖減去數字)。用引號包裝屬性可以解決這個問題。

+0

或'backgroundColor'保存3個字符:) –

+0

確實,我只是覺得在JS和CSS中解釋外殼會超出答案的範圍。 –

0

取而代之。

backgroundColor:'black'; 

或大衛建議

'background-color':'black'