那想问返回底部用哪个方法?我以为可以用scrollBottom呢?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>2-5、定位回到顶部</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
html,body {
width: 100%;
height: 100%;
font-size: 14px;
}
header {
height: 35px;
background: #666;
}
header a {
line-height: 35px;
color: #fff;
text-decoration: none;
margin: 0 15px;
}
.container {
height: 200%;
}
.backtop{
width:50px;
height:50px;
text-align:center;
padding-top: 13px;
background:grey;
color: white;
position: fixed;
right:0;
bottom:0;
}
.backbottom{
width:50px;
height:50px;
text-align:center;
padding-top: 13px;
background:grey;
color: white;
position: fixed;
top:0;
right:0;
}
</style>
</head>
<body>
<div class='backbottom'>
<span>返回<br/>底部</span>
</div>
<header>
<a href="">首页</a>
<a href="">新课程</a>
<a href="">热门课程</a>
</header>
<div class="container"></div>
<div class='backtop'>
<span>返回<br/>顶部</span>
</div>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.js"></script>
<script >
$(function(){
$('.backtop').on('click',function(event){
$('html,body').scrollTop(0);
});
$('.backbottom').click(function(){
$('html,body').scrollBottom(0);
})
})
</script>
</html>0
收起
正在回答 回答被采纳积分+1
3回答
JOYING1995
2018-07-24 14:13:23
$(document).scrollTop+$(window).height()=$(document).height();
所以要到底部应该是:$(document).height()-$(window).height();
前端小白入门系列课程
- 参与学习 人
- 提交作业 11218 份
- 解答问题 36712 个
从一个不会编程的小白到一个老司机是需要过程的,首先得入门,学习基础知识,然后才能进阶,最后再到精通,本专题是你走进前端世界的不二选择!
了解课程

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星