页面中返回顶部效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="shortcut icon" href="images/logo.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="static/font-awesome/css/font-awesome.min.css">
<script type="text/javascript" src="static/js/jquery.min.js"></script>
<style>
*{margin: 0px;padding: 0px;}
body{text-align: center;}
div{width: 1200px;height: 1500px;background: #eee;margin: 30px auto;}
a{text-decoration: none;color: #fff;}
p#back{text-align: center;position: fixed;bottom: 100px;right: 60px;background: #ccc;border-radius: 3px;height: 50px;width: 80px;display: none;}
p#back .fa{font-size: 30px;}
p a span:hover{background-color: red;}
</style>
<script>
$(function() {
$(window).scroll(function(){
if($(window).scrollTop()>150){
$('#back').fadeIn(1000)
}else{
$('#back').fadeOut(1000)
}
})
})
</script>
</head>
<body>
<a href=""></a>
<div>网页内容</div>
<p id="back"><a href=""><span class="fa fa-arrow-circle-up"></span><br> 返回顶部</a></p>
</body>
</html>