2011-04-26 142 views
0

我想讓jquery水平地動畫一些長佈局,但似乎無法使其工作。我懷疑是一個遍歷問題,但嘗試了幾個小時,無法修復。請提前幫助和感謝。jquery遍歷

我試圖讓「innerlonglayout」水平滾動,點擊按鈕。

這裏是我的代碼:

<div id="innermask"> 
    <div id="innerlonglayout"> 
    <div class="container-bits">Content Here</div> 
    <div class="container-bits">Content Here</div> 
    <div class="container-bits">Content Here</div> 
    <div class="container-bits">Content Here</div> 
    <div class="container-bits">Content Here</div> 
    <div class="container-bits">Content Here</div> 
    </div> 
</div> 
<div class="boxmenu"> 
      <span id="2002"><img src="images/butt_2002.png"></span> 
      <span id="2003"><img src="images/butt_2003.png"></span> 
      <span id="2004"><img src="images/butt_2004.png"></span> 
      <script> 
       $("#2002").click(function() { 
        $("#2002").parent().parent().parent().children().children().animate({position:'fixed',left:'30px'}, "slow"); 
       }); 
       $("#2003").click(function() { 
        $("#2002").parent().parent().children().children().animate({position:'fixed',left:'-300px'}, "slow"); 
       }); 
       $("#2004").click(function() { 
        $("#2002").parent().parent().children().children("#innerlonglayout").animate({position:'fixed',left:'-600px'}, "slow"); 
       }); 
       </script> 
     </div> 

這裏是我的CSS:

#innermask{ 
width:500px; 
height:250px; 
    border:1px solid #cc61b8; 
    overflow:hidden; 
} 

#innerlonglayout{ 
    width:10000px;   // just an example 
} 

.container-bits{ 
    width:250px; 
    height:498px; 
    float:left; 
} 
+3

你想完成什麼? – 2011-04-26 18:32:33

+0

你確定你需要所有這些代碼嗎? ();'('position''fixed',left:' - 300px'},'slow');''''''''做一個更簡單的方法,它會讓你的代碼更易於理解。還要確保你的CSS是正確的,所有的'span'都在同一行上。試着在你的'#innermask'中運行沒有溢出:隱藏的程序 – 2011-04-26 18:57:02

回答

0

這有可能是你的數字ID與您的jQuery搞亂。嘗試使用以字母開頭的唯一ID。

+1

在任何情況下,以數字開頭的id值是錯誤](http://www.w3.org/TR/html40/types。 HTML#類型名)。 – Paolo 2011-04-26 18:40:35

+0

@guand是的,那也是絕對正確:) – Jason 2011-04-26 18:42:46

1

我發現了什麼問題。

爲了使用jquery來動畫任何東西,你必須設置位置:Div的絕對值。

謝謝大家的回覆。