<html>
<head>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var h = 0
  $(".btn1").click(function(){
h += 100;
    $("div").scrollTop(h);
  });
  $(".btn2").click(function(){
if(h<=0){
return;
}
    h -= 100;
    $("div").scrollTop(h);
  });
});
</script>
</head>
<body>
<div style="border:1px solid black;width:200px;height:200px;overflow:auto">
This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
</div>
<button class="btn1">down</button>
<br />
<button class="btn2">up</button>
</body>
</html>

解决方案 »

  1.   

    我从W3C网上复制来的
    http://www.w3school.com.cn/jquery/css_scrolltop.asp
      

  2.   

    我从W3C网上复制来的
    http://www.w3school.com.cn/jquery/css_scrolltop.asp不过还是谢谢你啊!
      

  3.   


    呃,你这个还有点小问题哦。当我用滚轮滚到中间位置在用按钮点的话,他会从默认的0位置开始滚动。所以要加点代码,就是在滚动条当前位置的地方开始滚动。
    加个h=$("#cc").scrollTop();在每个按钮事件里面。
      

  4.   


    呃,你这个还有点小问题哦。当我用滚轮滚到中间位置在用按钮点的话,他会从默认的0位置开始滚动。所以要加点代码,就是在滚动条当前位置的地方开始滚动。
    加个h=$("#cc").scrollTop();在每个按钮事件里面。
    这个只是演示用,实际使用还得根据需求改
      

  5.   


    呃,你这个还有点小问题哦。当我用滚轮滚到中间位置在用按钮点的话,他会从默认的0位置开始滚动。所以要加点代码,就是在滚动条当前位置的地方开始滚动。
    加个h=$("#cc").scrollTop();在每个按钮事件里面。
    这个只是演示用,实际使用还得根据需求改对哦。