2012-02-12 105 views
1

我正在爲我的社交網絡進行聊天。我使用下面的代碼,它似乎在顯示聊天時工作,但不隱藏它。您可以在右下角的http://live-pin.com(「system」欄)上看到它。如果css()== X,否則不起作用,表單不起作用

我在做什麼壞事?

function toggleChat(obj){ 
    current_margin = $(obj).css('marginBottom'); 
    if (current_margin == 0){ 
      $(obj).animate({marginBottom : "-270px"}).removeClass("active_box").addClass("hidden_box"); 
    }else{ 
     $(obj).animate({marginBottom : "0"}).removeClass("hidden_box").addClass("active_box"); 
    } 
} 

另外,我有麻煩,因爲它顯示/隱藏兩個聊天&我不希望這樣的事情發生,而「新郵件」的形式不工作,只是在最後創建的聊天。作爲附加細節,這些框是使用從JSON檢索的數據動態創建的,因此我不能使用click()函數或類似工具。

<?php echo "謝謝! (:"; ?>

+0

你是怎麼稱呼你的功能的?你可以發佈那個部分嗎? – elclanrs 2012-02-12 18:31:38

+1

你的問題不清楚 – ShankarSangoli 2012-02-12 18:32:19

回答

2

即使你可以設置的marginBottom爲0,將在內部是0像素,從而current_margin0px這是不0 但你可以嘗試先解析值:

function toggleChat(obj) { 
    var currentMargin = parseInt($(obj).css('margin-bottom')); 
    if (currentMargin === 0) { 
    $(obj).animate({ marginBottom: "-270px" }) 
      .removeClass("active_box") 
      .addClass("hidden_box"); 
    } else { 
    $(obj).animate({marginBottom : "0px"}) 
      .removeClass("hidden_box") 
      .addClass("active_box"); 
    } 
} 
+0

它幫助了我,但它沒有解決它。 – Luis 2012-02-12 23:29:39