基本信息
源码名称:页面返回顶部
源码大小:1.28KB
文件格式:.html
开发语言:js
更新时间:2014-04-15
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#goTopBtn{
width: 50px;
height: 50px;
background: red;
position: fixed;
right: 0px;
bottom: 10px;
display: none;
}
</style>
</head>
<body style='height:1200px;'>
<div id="goTopBtn" class="goTopBtn"><a href="javascript:;" title="我要上去!" alt="回到顶部" /></a></div>
<script src='jquery.js'></script>
<script type="text/javascript">
$(window).scroll(function () {
if($(window).scrollTop() >= 300)//距离顶部多少高度显示按钮
{
$('#goTopBtn').slideDown(200);
}else
{
$('#goTopBtn').slideUp(200);
}
});
$('#goTopBtn').click(function(){
$('body,html').animate({scrollTop:0},500)
});
//按钮定位
var win_width= $(window).width(); //窗口宽度
var content_width= $('.wrap').width(); //容器宽度
var topbtn_width= $('#goTopBtn').width(); //按钮宽度
//alert([win_width - content_width]/2);
//距离主体部分的右侧距离
var topbtn_posi = ([win_width - content_width ]/2 - topbtn_width - 10);
$('#goTopBtn').css({'right':topbtn_posi});
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#goTopBtn{
width: 50px;
height: 50px;
background: red;
position: fixed;
right: 0px;
bottom: 10px;
display: none;
}
</style>
</head>
<body style='height:1200px;'>
<div id="goTopBtn" class="goTopBtn"><a href="javascript:;" title="我要上去!" alt="回到顶部" /></a></div>
<script src='jquery.js'></script>
<script type="text/javascript">
$(window).scroll(function () {
if($(window).scrollTop() >= 300)//距离顶部多少高度显示按钮
{
$('#goTopBtn').slideDown(200);
}else
{
$('#goTopBtn').slideUp(200);
}
});
$('#goTopBtn').click(function(){
$('body,html').animate({scrollTop:0},500)
});
//按钮定位
var win_width= $(window).width(); //窗口宽度
var content_width= $('.wrap').width(); //容器宽度
var topbtn_width= $('#goTopBtn').width(); //按钮宽度
//alert([win_width - content_width]/2);
//距离主体部分的右侧距离
var topbtn_posi = ([win_width - content_width ]/2 - topbtn_width - 10);
$('#goTopBtn').css({'right':topbtn_posi});
</script>
</body>
</html>