2011-05-15 56 views
0

滑出是沒有問題的,我只對自己在那不滑的問題出現了,我覺得它沒有趕上他們的第一個IF寬度爲0像素。對不起,我真的很喜歡jQuery。問題滑入式輸入/輸出的JQuery

CODE:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
    $("#ShowHideComment").click(function(){ 
     if ($(".iframe_comment").width() == "0px"){ 
      $(".iframe_comment").animate({width: "800px"}, {queue:false, duration:1000}); 
     } 
     else{ 
      $(".iframe_comment").animate({width: "0px"}, {queue:false, duration:1000 
      }); 
     } 
    }); 
}); 
</script> 

回答

1

the docs

所有動畫屬性應該爲動感的單一數值

你不處理CSS屬性值這裏,但是用普通的整數。

$(document).ready(function(){ 
    $("#ShowHideComment").click(function(){ 
     var $comment = $(".iframe_comment"); 
     if ($comment.width() == 0){ 
      $comment.animate({width: 800}, {queue:false, duration:1000}); 
     } 
     else{ 
      $comment.animate({width: 0}, {queue:false, duration:1000}); 
     } 
    }); 
}); 

see width()也:

.css(width).width()之間的區別是,後者 返回一個無單位的像素值

+0

哇涼的感謝託默勒格...我怎樣才能添加功能,當完成動畫?我嘗試添加功能(){在持續時間:1000。它不工作.. – user453089 2011-05-15 09:19:50

+0

有一個'animate()'完整的參數。把你的回調函數放在那裏。另外,你真的不需要'queue:false'。只要沒有其他動畫已經開始,您的動畫將始終立即開始。 – Tomalak 2011-05-15 09:23:28

+0

這裏我嘗試:'$ comment.animate({寬度:0},{隊列:假,持續時間:450,函數(){$ comment.hide()}});'然後不工作=/ – user453089 2011-05-15 09:28:20

0

.width()返回數值。 此行if ($(".iframe_comment").width() == "0px") 應該 if ($(".iframe_comment").width() == 0)