是不是可以使用jQuery(或其他库)滚动div *而不使用*?

时间:2012-05-25 08:12:58

标签: javascript html css html5

我想使用任何库以编程方式滚动div而不使用。是否可能,如果可能,怎么样?

谢谢。

2 个答案:

答案 0 :(得分:5)

是的,是的。

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

答案 1 :(得分: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>