返回顶部和回到底部

经常会有返回顶部、回到底部的需求,推荐一种比较简单的写法
JQ中有 scrollTop() 方法可以帮助我们快速实现该需求

示例:


<html>
<body >
<div class="div1" style="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.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  onclick="test()">测试返回</butoon>
</body>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
	function test(){
		 $(".div1").scrollTop(0);//此为滚动条的位置--返回顶部
		 $(".div1").scrollTop($(document).height());//此为滚动条的位置---返回底部 直接取dom的高度
	}
</script>
</html>

猜你喜欢

转载自blog.csdn.net/qq_28584685/article/details/97248433
今日推荐