<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
height: 2000px;
}
button{
width: 150px;
height: 100px;
color: red;
font-size: 30px;
position: fixed;
right: 10px;
bottom: 10px;
display: none;
}
</style>
</head>
<body>
<!-- 要求:做一个固定到页面右下角的按钮,点击时返回页面的顶部(按钮仍然不动,是当前屏幕的顶端回到页面顶部),要求该按钮只有在滚动距离超过200px时才能看见 -->
<button>返回顶部</button>
<script src="jquery-1.10.1.min.js"></script>
<script>
$("button").css("display",$(window).scrollTop()>200?"block":"none");
$(window).scroll(function (){
$("button").css("display",$(window).scrollTop()>200?"block":"none");
})
$("button").click(function (){
$(window).scrollTop(0);
})
</script>
</body>
</html>
练习-返回顶部
最新推荐文章于 2022-11-28 00:03:39 发布