2010-05-12 55 views

Trả lời

1

ví dụ đơn giản để trượt một div trên trang:

<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> 

Bạn có thể cải thiện nó theo nhu cầu của bạn, nhưng điều này có thể được sử dụng như một ý tưởng cơ bản làm thế nào để làm điều đó.

+0

Lỗi Tên 'MovingContent' không tồn tại trong hiện tại bối cảnh \t E: \ Hemaa \ Mẫu \ welcome.aspx nhận lỗi này – TinTin

+0

Tôi vừa chỉnh sửa để sửa chữa các lỗi. Thử lại. Lỗi cuối cùng mà tôi đã sửa đã thay đổi 'ClientId => ClientID'. Bây giờ nó sẽ làm việc (Tôi đã thử nghiệm nó bây giờ ...) – awe

+0

tôi không nhận được bất cứ điều gì trong trang của tôi .. sau khi chạy trang. – TinTin

Các vấn đề liên quan