-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex8.html
More file actions
59 lines (54 loc) · 1.68 KB
/
index8.html
File metadata and controls
59 lines (54 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Javascript 回到顶部效果</title>
<!-- <link rel="stylesheet" type="text/css" href="style.css" /> -->
<style>
#btn {
width:40px;
height:40px;
position:absolute; /* //固定定位设置 */
left:50%;
margin-left:610px;
bottom:30px;
background:url(http://img.mukewang.com/535e0dc100010e9c00400080.jpg) no-repeat left top;
display:none;
position:fixed;
}
#btn:hover {
background:url(http://img.mukewang.com/535e0dc100010e9c00400080.jpg) no-repeat 0 -39px;
}
.box {
width:1190px;
/* //实现大图居中 */
margin:0 auto;
}
</style>
</head>
<body>
<div class="box">
<img src="http://img.mukewang.com/535e0ce800015b7511902787.jpg" />
</div>
<a href="javascript:;" id="btn" title="回到顶部"></a>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
<script>
$(function () {
$(window).scroll(function () {
var h = $(window).height();
var scrolls = $(this).scrollTop();
var lazyheight = parseFloat(h) + parseFloat(scrolls);
if (lazyheight - 200 > h) {
$("#btn").show();
} else {
$("#btn").hide();
}
})
$("#btn").click(function () {
$('body,html').animate({
scrollTop: 0
}, 500);
})
})
</script>
</body>
</html>