首页 > 其他 > 详细

jq简单实现点击回到顶部功能

时间:2017-03-12 19:31:57      阅读:152      评论:0      收藏:0      [点我收藏+]

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="js/jquery-2.1.0.js" ></script>
<title></title>
<style>
.gao{
width: 100%;
height: 1100px;
}
.top{
width: 80px;
height: 60px;
line-height: 60px;
position:fixed;
right: 10px;
bottom: 30px;
background: green;
color: white;
text-align: center;
display: none;
cursor: pointer;
}
</style>
</head>
<body>
<div class="gao"></div>
<div class="top">回到顶部</div>
</body>
<script>
$(document).scroll(function(){
var scrtops = $(document).scrollTop();
if(scrtops>110){
$(‘.top‘).fadeIn();
}else{
$(‘.top‘).fadeOut();
}
console.log(scrtops)
})
$(‘.top‘).click(function(){
var s =$(‘body‘).scrollTop();
$(‘body‘).animate({scrollTop:0},100)
})
</script>
</html>

jq简单实现点击回到顶部功能

原文:http://www.cnblogs.com/yangjiansong/p/6538711.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!