运行代码 缩小
汉王
HTML代码
复制 格式化 注释 注释 清空
放大
AخA
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
<html xmlns="http://www.w3.org/1999/xhtml">
3
<head>
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
<title>“回到顶部”功能代码</title>
6
<style type="text/css">
7
#demo {height: 2000px; position: relative;}
8
#demo p a { position: absolute; bottom: 20px;}
9
</style>
10
<script type="text/javascript" src="//apps.bdimg.com/libs/jquery/1.11.3/jquery.min.js"></script>
11
<script type="text/javascript">
12
$(function() {
13
    $('#to-top').click(function() {
14
        $('html, body').animate({ scrollTop : 0}, 'fast');
15
        return false;
16
    });
17
});
18
</script>
19
</head>
20
<body>
21
<div id="demo">
22
<p><a href="#" id="to-top">回到顶部</a></p>
23
</div>
24
</body>
25
</html>
CSS代码
复制 格式化 注释 注释 颜色 清空
放大
CSS代码...
x
 
1
JS代码
复制 格式化 注释 注释 清空
放大
JS代码...
xxxxxxxxxx
1
 
1
名称
超简单的滑动“回到顶部”功能代码
分类
网站常用
描述
让网页快速回到顶部的功能,为了避免呆板,这里加入了jQuery动画效果,让用户在点击“回到顶部”之后,页面迅速滑动至网页的最顶部,代码看起来似乎也不复杂。这里需要注意几个参数:fast改成slow, 0数字代表position的距离,0是到页顶,...
收藏