首页 新闻 会员 周边

如果要在博客园的博客里加一个返回顶部的按钮式代码怎么写

0
悬赏园豆:20 [已解决问题] 解决于 2011-12-07 10:01

rt,我说的是点击一个按钮 回到页面的顶部去

落尘祥的主页 落尘祥 | 初学一级 | 园豆:86
提问于:2011-12-04 10:31
< >
分享
最佳答案
1

示例代码:

<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(
function(){
$(
'#returnTop').click(function () {
$(
'html,body').animate({ scrollTop: '0px' }, 800);
returnfalse;
});
});
</script>
</head>
<body>
<div style="height:2000px">
abc
</div>
<a href="###" id="returnTop" style="bottom: 10px;position: fixed;right: 10px;font-size: 16px;">returnTop</a>
</body>
</html>

你只要在 博客的"管理"->"设置"->"页脚Html代码"中加上

<a href="###" id="returnTop" style="bottom: 10px;position: fixed;right: 10px;font-size: 16px;">returnTop</a>

$(function(){
$(
'#returnTop').click(function () {
$(
'html,body').animate({ scrollTop: '0px' }, 800);
returnfalse;
});
});
就可以了,博客中已经加了jquery。
收获园豆:20
artwl | 专家六级 |园豆:16736 | 2011-12-05 12:03
其他回答(1)
0

在顶部添加一个锚,在按钮事件里面定位到锚就可以了

小小刀 | 园豆:1991 (小虾三级) | 2011-12-04 11:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册