-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcss弹出动画(头部和底部).html
94 lines (84 loc) · 2.17 KB
/
css弹出动画(头部和底部).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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover">
<title>css弹出动画(头部和底部)</title>
<style type="text/css">
*{margin:0;padding:0;}
.moveFromBottom{
position: fixed;
left: 0;
right: 0;
bottom: 0;
opacity: 0;
-webkit-transform: translate(0, 100%);
transform: translate(0, 100%);
-webkit-transition: all ease-in-out .3s;
transition: all ease-in-out .3s;
}
.moveFromTop{
position: fixed;
left: 0;
right: 0;
top: 0;
opacity: 0;
-webkit-transform: translate(0, -100%);
transform: translate(0, -100%);
-webkit-transition: all ease-in-out .3s;
transition: all ease-in-out .3s;
}
.showMove {
opacity: 1;
-webkit-transform: translate(0, 0);
transform: translate(0,0);
}
.box{
width: 100%;
height: 300px;
background: #fff;
z-index: 10;
}
.mask{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, .5);
display: none;
}
</style>
</head>
<body>
<div class="mask"></div>
<button id="btnDown">点击从底部弹出</button>
<button id="btnUp">点击从顶部弹出</button>
<div id="box1" class="box moveFromBottom">
从底部弹出效果
</div>
<div id="box2" class="box moveFromTop">
从顶部弹出效果
</div>
</body>
<script type="text/javascript">
let btnDown =document.getElementById('btnDown');
let btnUp =document.getElementById('btnUp');
let box1 =document.getElementById('box1');
let box2 =document.getElementById('box2');
let maskShow = document.querySelector(".mask")
maskShow.onclick=function(){
box1.classList.remove("showMove")
box2.classList.remove("showMove")
maskShow.style.display='none'
}
btnDown.onclick=function(){
maskShow.style.display='block'
box1.classList.add("showMove")
}
btnUp.onclick=function(){
maskShow.style.display='block'
box2.classList.add("showMove")
}
</script>
</html>