2012-02-12 103 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