-
Notifications
You must be signed in to change notification settings - Fork 3
/
alert-window.html
146 lines (123 loc) · 2.74 KB
/
alert-window.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
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
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.alert-window {
width: 500px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #fff;
border-radius: 4px;
z-index: 3;
display: none;
}
.cover {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: #ccc;
z-index: 2;
}
.clearfix:after {
content: '';
display: block;
clear: both;
}
.header {
position: relative;
border-bottom: 1px solid #ccc;
height: 36px;
line-height: 36px;
}
.header h2 {
padding-left: 10px;
margin-top: 5px;
}
.header button {
float: right;
border: none;
background-color: #fff;
position: absolute;
top: 0;
right: 10px;
font-size: 20px;
outline: none;
cursor: pointer;
}
.content {
margin-top: 10px;
margin-left: 10px;
}
.footer button {
float: right;
border: none;
background-color: #fff;
outline: none;
cursor: pointer;
margin-right: 10px;
margin-top: 10px;
margin-bottom: 10px;
font-size: 16px;
}
.footer {
border-top: 1px solid #ccc;
}
</style>
</head>
<body>
<button class="click-me">点我</button>
<div class="alert-window">
<div class="header clearfix">
<h2>我是标题</h2>
<button class="close">×</button>
</div>
<div class="content">
<p>我是内容</p>
<p>我是内容</p>
</div>
<div class="footer clearfix">
<button class="close">取消</button>
<button>确定</button>
</div>
</div>
<script>
var clickMe = document.querySelector('.click-me');
var close1 = document.querySelector('.header > .close');
var close2 = document.querySelector('.footer .close');
var alertWindow = document.querySelector('.alert-window');
// function fn (n) {
// n.stopPropagation();
// alertWindow.style.display = 'block';
// document.body.classList.add('cover');
// }
clickMe.addEventListener('click', function (e) {
e.stopPropagation();
alertWindow.style.display = 'block';
document.body.classList.add('cover');
});
close1.addEventListener('click', function () {
alertWindow.style.display = 'none';
document.body.classList.remove('cover');
})
close2.addEventListener('click', function () {
alertWindow.style.display = 'none';
document.body.classList.remove('cover');
})
window.addEventListener('click', function (e) {
alertWindow.style.display = 'none';
document.body.classList.remove('cover');
});
alertWindow.addEventListener('click', function (e) {
e.stopPropagation();
});
</script>
</body>
</html>