<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.box {
width: 200px;
height: 1990px;
background: pink;
}
.backTop {
padding: 20px;
background: red;
color: #fff;
position: fixed;
bottom: 50px;
right: 50px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="box">
这是一个长盒子
</div>
<div class="backTop">
返回顶部
</div>
</body>
</html>
<script src="../jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
window.onscroll = function() {
//获取当前的scrollTop
var current_top = $(window).scrollTop();
if(current_top > 100) {
$(".backTop").show();
} else {
$(".backTop").hide();
}
};
function GoTop() {
$(window).scrollTop(0);
}
$('.backTop').click(function() {
GoTop();
})
</script>
点击返回顶部
最新推荐文章于 2023-11-12 19:12:34 发布