2011-09-13 31 views
1

任何人都可以幫助我嗎?animate({top:' - = dynamic value'},xxx)

我想做一個自動滾動上下div元素的內容。爲此,我使用.animate()。這裏是我的jQuery代碼片段:

$(document).ready(function() { 
$('.jspPane').animate({ top: '-=100' }, 2000).animate({ top: '+=100' }, 2000).stop();}); 

HTML看起來像這樣:

<div class="widgetInnerWrapper"> 
    <div class="widget logos"> 
     <div class="title"> 
      <h3> 
       Membership</h3> 
     </div> 
     <div class="widgetContent"> 
      <div class="scrollContentWrapper"> 
       <div class="scroll-pane"> 
        <div id="logosFull"> 
         <div id="logosBottom"> 
         </div> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

我設法做得到它與設定值工作,但div的內容可能會改變,我想問:

我可以以某種方式替換頂部值' - = 100'和'+ = 100'與動態?或者用別的東西替換動畫?

回答

4

當然,你可以動態創建動畫值,只要他們下定決心,字符串:

var maxX = 200; 
$('.jspPane').animate({ top: '-=' + maxX }, 2000); 
+0

非常感謝你:) – Vikita

0

您需要使用字符串連接:

top: "-=" + someValue