-
Notifications
You must be signed in to change notification settings - Fork 0
/
2回到顶部按钮出现消失效果.html
53 lines (53 loc) · 1.33 KB
/
2回到顶部按钮出现消失效果.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, width=device-width"/>
<title></title>
<style>
html{
height:2500px;
}
a{
text-decoration: none;
color: #fff;
}
.cd-top{
border-radius: 50%;
position: fixed;
width: 50px;
line-height:50px;
text-align: center;
height: 50px;
right: 30px;
background: #848484;
opacity: 0.8;
box-shadow: 0 0 10px rgba(0,0,0,.05);
white-space: nowrap;
-webkit-transition: all .3s;
transition: all .3s;
z-index: 99;
transform: translateX(200%);
}
.cd-top.cd-is-visible{
transform: none;
}
</style>
</head>
<body>
<a class="cd-top" href="#">
Top
</a>
<script>
var $top = document.querySelector('.cd-top');
window.addEventListener('scroll',function(){
if(window.scrollY > 100){
$top.className = 'cd-top cd-is-visible';
}else{
$top.className = 'cd-top';
}
});
</script>
</body>
</html>