2010-05-12 42 views

回答

1

簡單的例子,一個div在頁面上滑動:

<asp:Panel id="MovingContent" runat="server" 
    style="position:absolute;left:-100px;top:20px;height:40px;width:100px;"> 
The content that will move 
</asp:Panel> 

<script type="text/javascript"> 

//Initial position 
//(should be the same as the position specified in the element's style) 
posX = -100; 
posY = 20; 

//Position where the element will stop 
targetX=200; 
targetY=60; 

function move(){ 
if(posX < targetX){ 
    posX += 10; 
    if(posY < targetY) posY += 1; 
    var divElement = document.getElementById('<%=MovingContent.ClientID%>'); 
    divElement.style.left = posX + 'px'; 
    divElement.style.top = posY + 'px'; 

    //Time in milliseconds to when to move next step 
    self.setTimeout('move()', 100); 

} 
} 

move(); //Start the moving 

</script> 

你可以根據自己的需要來改進它,但這可以作爲一個基本的想法。

+0

錯誤 'MovingContent' 並不在當前情況下\t E類的名稱:\ Hemaa \表格\ welcome.aspx 得到這個錯誤 – TinTin 2010-05-12 12:26:16

+0

我剛纔編輯的修復錯誤。再試一次。我修正的最後一個錯誤是改變'ClientId => ClientID'。現在它應該工作(我已經測試了它...) – awe 2010-05-12 12:28:47

+0

我沒有得到任何東西在我的頁面..運行頁面後。 – TinTin 2010-05-12 12:57:53