2012-05-25 35 views

回答

5

是的。

var myEl = document.getElementById('myEl'); 
myEl.scrollLeft = 12; 
myEl.scrollTop = 34; 
+0

我實際上已經嘗試過,但沒有工作 - 只是在錯誤的div上調用它.... arrgh !!! –

0

是的,這是可能的。試試這個代碼。

<html> 
<head><title>Scrolling a DIV with JavaScript</title> 

<script language='javascript'> 

    function move_up() { 
    scroll_clipper.scrollTop = 0; 
    } 

</script> 

</head> 
<body> 

    <a href='javascript:move_up()'>Move UP</a> 

    <p> 

    <div id='scroll_clipper' style='position:absolute; width:150px; height: 150px; overflow:auto'> 
    <div id='scroll_text' style='background-color:yellow'> 
     Here is some content that can be scrolled. 
     <p>It uses two divs:<ul> 
     <li>scroll_clipper, and 
     <li>scroll_text 
     </ul> 

     scroll_clipper defines the scroll area while scroll_text 
     defines the text to be scrolled. 

    </div> 
    </div> 

</body> 
</html>