网页滚动到顶部特效

网页滚动到顶部特效

背景图:背景图

直接贴上源代码:

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta charset="utf-8" />
<script src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>

<script type="text/javascript">
$(function () {
var c, a = $("#rocket-to-top"), e = ($(document).scrollTop(), !0);
$(window).scroll(function () {
var b = $(document).scrollTop(); 0 == b ? "0px 0px" == a.css("background-position") ? a.fadeOut("slow") : e && (e = !1, $(".level-2").css("opacity", 1), a.delay(100).animate({ marginTop: "-1000px" }, "normal", function () { a.css({ "margin-top": "-125px", display: "none" }), e = !0 })) : a.fadeIn("slow")
}), a.hover(function () { $(".level-2").stop(!0).animate({ opacity: 1 }) }, function () { $(".level-2").stop(!0).animate({ opacity: 0 }) }), $(".level-3").click(function () { function b() { var b = a.css("background-position"); if ("none" == a.css("display") || 0 == e) return clearInterval(c), a.css("background-position", "0px 0px"), void 0; switch (b) { case "0px 0px": a.css("background-position", "-298px 0px"); break; case "-298px 0px": a.css("background-position", "-447px 0px"); break; case "-447px 0px": a.css("background-position", "-596px 0px"); break; case "-596px 0px": a.css("background-position", "-745px 0px"); break; case "-745px 0px": a.css("background-position", "-298px 0px") } } e && (c = setInterval(b, 50), $("html,body").animate({ scrollTop: 0 }, "slow")) })
});
</script>
<style>
/*回到顶部*/
#rocket-to-top div {
left: 0;
margin: 0;
overflow: hidden;
padding: 0;
position: absolute;
top: 0;
width: 149px;
}

#rocket-to-top .level-2 {
background: url("336693-20160929114645844-1059340274.png") no-repeat scroll -149px 0 transparent;
display: none;
height: 250px;
opacity: 0;
z-index: 1;
}

#rocket-to-top .level-3 {
background: none repeat scroll 0 0 transparent;
cursor: pointer;
display: block;
height: 150px;
z-index: 2;
}

#rocket-to-top {
background: url("336693-20160929114645844-1059340274.png") no-repeat scroll 0 0 transparent;
cursor: default;
display: block;
height: 250px;
margin: -125px 0 0;
overflow: hidden;
padding: 0;
position: fixed;
right: 0;
top: 80%;
width: 149px;
z-index: 11;
}
</style>
</head>

<body>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>
<span>这里是内容</span></br>

<div style="display: none;" id="rocket-to-top">
<div style="opacity: 0; display: block;" class="level-2"></div>
<div class="level-3"></div>
</div>
</body>

</html>