-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_alert_manual.html
392 lines (371 loc) · 10.7 KB
/
my_alert_manual.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>我的对话框使用手册</title>
<link rel="stylesheet" href="./my_popup.css">
<link rel="stylesheet" href="./my_alert.css">
<style>
* {
margin: 0;
padding: 0;
}
.main {
margin: 0 auto;
padding: 40px 0;
width: 1000px;
}
h2 {
margin-bottom: 20px;
font-size: 24px;
letter-spacing: 3px;
text-align: center;
line-height: 50px;
}
.synopsis {
margin-bottom: 20px;
}
ol {
padding: 0 16px;
}
li {
margin-bottom: 20px;
}
h3 {
margin-bottom: 10px;
font-weight: normal;
font-size: 16px;
}
p {
margin-bottom: 10px;
}
pre {
margin: 10px 0;
padding: 2px 2px 2px 8px;
border-left: 3px solid #3C948B;
background: #f1f2f0;
line-height: 1.4;
font-size: 16px;
white-space: pre-wrap;
}
button {
padding: 0 10px;
background: #88CAD6;
border: none;
border-radius: 3px;
outline: medium;
cursor: pointer;
color: #fff;
line-height: 32px;
}
button:hover {
background: #6CA7B2;
}
table {
margin-top: 20px;
width: 100%;
border: 1px solid #999;
}
table th {
padding: 10px 0;
background: #EAFAFC;
text-align: center;
}
table td {
padding: 10px;
}
table td:first-child {
width: 160px;
}
.red {
color: red;
}
.gray {
color:gray;
}
</style>
</head>
<body>
<div class="main">
<h2>我的对话框插件的使用方法</h2>
<p class="synopsis"><b>功能说明</b>:对话框插件基于弹窗插件,引入my_alert.js后会在window上绑定一个MyPopup构造函数的oMyAlert实例。该实例有五个方法show、close、chagneMsg、addClass、removeClass。对话框的显隐是使用的添加删除节点的方式,每一次的显示都是一个新的节点,在就节点没有被删除的情况下在调用show方法也不会创建另一个节点。</p>
<ol>
<!-- 对话框1说明 -->
<li>
<h3>只传文本,最简单的显示方式</h3>
<pre><code>var oOneShow = document.getElementById('oneShow');
oOneShow.onclick = function () {
oMyAlert.show('我是谁?');
}
</code></pre>
<button id="oneShow">显示对话框</button>
<p class="tip">说明:这一种最简单的显示方式,即不设置按钮,会在1.5秒之后自动关闭对话框。</p>
</li>
<!-- 对话框2说明 -->
<li>
<h3>配置参数、方法</h3>
<pre><code>
var oTwoShow = document.getElementById('twoShow');
oTwoShow.onclick = function () {
var iNum = 0;
oMyAlert.show('我是谁?', {
bgclose: false, // 是否可以点击背景关闭对话框(默认false不能)
bgcolor: '#999' // 背景颜色(默认transparent)
opacity: 0.2, // 背景透明度(默认0)
msgAlign: 'c', // 消息文本的对齐方式:l -> 左对齐;c -> 居中对齐(默认);r -> 右对齐
btnAlign: 'c', // 按钮的对齐方式:l -> 左对齐;c -> 居中对齐(默认);r -> 右对齐
aBtnTxt: ['确定', '取消', '关闭'], // 按钮的个数及其文本(默认无按钮)
btn1: function () { // btn1对应第一个按钮,btn+n对应第n个按钮的点击事件,如果不设置对应的事件,默认为调用close()关闭弹窗
if ( iNum == 0 ) {
oMyAlert.changeMsg('我是确定按钮,再点我就要消失了!');
iNum = 1;
} else {
oMyAlert.close();
}
},
btn2: function () {
iNum = 0;
oMyAlert.changeMsg('我是取消按钮,你点我呀!');
},
showFn: function () {
oMyAlert.addClass('state1');
}
});
}
</code></pre>
<button id="twoShow">显示对话框</button>
<table rules="all">
<thead>
<tr>
<th colspan="2">配置参数</th>
</tr>
</thead>
<tbody>
<tr>
<td>msg</td>
<td>必须。show方法的第一个参数,是将要显示的对话框的文本</td>
</tr>
<tr>
<td>bgclose</td>
<td>可选。true,false。是否可以点击背景关闭对话框(默认false不能)</td>
</tr>
<tr>
<td>bgcolor</td>
<td>可选。背景颜色(默认transparent)</td>
</tr>
<tr>
<td>opacity</td>
<td>可选。背景透明度(默认0)</td>
</tr>
<tr>
<td>msgAlign</td>
<td>可选。消息文本的对齐方式:l -> 左对齐;c -> 居中对齐(默认);r -> 右对齐</td>
</tr>
<tr>
<td>btnAlign</td>
<td>可选。按钮的对齐方式:l -> 左对齐;c -> 居中对齐(默认);r -> 右对齐</td>
</tr>
<tr>
<td>aBtnTxt</td>
<td>可选。按钮的个数及其文本(默认无按钮)</td>
</tr>
<tr>
<td>btn+n</td>
<td>可选。这个是按钮的方法,btn1就是aBtnTxt中第一个按钮的点击方法。如aBtnTxt中的按钮没有对应的btn方法,将默认为点击关闭对话框。</td>
</tr>
<tr>
<td>showFn</td>
<td>可选。在弹窗显示之前执行的函数,注意是一个同步函数哈。</td>
</tr>
</tbody>
</table>
<table rules="all">
<thead>
<tr>
<th colspan="2">方法</th>
</tr>
</thead>
<tbody>
<tr>
<td>show</td>
<td>最重要的方法,调用该方法会添加并显示对话框</td>
</tr>
<tr>
<td>close</td>
<td>关闭对话框</td>
</tr>
<tr>
<td>changeMsg</td>
<td>调用该方法,将改变对话框中的文本</td>
</tr>
<tr>
<td>addClass</td>
<td>调用该方法将给弹窗的popup-content添加类名</td>
</tr>
<tr>
<td>removeClass</td>
<td>调用该方法将给弹窗的popup-content删除类名</td>
</tr>
</tbody>
</table>
</li>
<!-- 对话框3说明 -->
<li>
<h3>可以根据自己的需求改变默认的弹窗样式,或者是设置多种样式然后在显示的时候决定用那种样式。</h3>
<pre><code><span class="gray">// my_alert.css文件第一行,这是对话框默认样式</span>
.my-alert .popup-content {
padding: 0;
background: #424F63;
color: #fff;
font-size: 14px;
}
</code></pre>
<pre><code><span class="gray">// my_alert.css,要自定义弹窗样式可以在my_alert.css文件最下面这样写</span>
.my-alert .state1 {
background: #71B69A;
border: 1px solid #3E7D6C;
border-radius: 10px;
box-shadow: 0 0 10px #aaa;
color: #fff;
}
.my-alert .state2 {
background: #EDEECF;
border: 2px solid #EDEECF;
border-radius: 4px;
box-shadow: 0 0 10px #aaa;
color: #7B2025;
}
</code></pre>
<pre><code><button id="threeShow1">默认样式</button>
<button id="threeShow2">样式一</button>
<button id="threeShow3">样式二</button>
********************************************************
var oThreeShow1 = document.getElementById('threeShow1');
var oThreeShow2 = document.getElementById('threeShow2');
var oThreeShow3 = document.getElementById('threeShow3');
oThreeShow1.onclick = function () {
oMyAlert.show('我是默认样式,我有按钮', {
bgcolor: '#999',
opacity: 0.2,
aBtnTxt: ['确定']
})
}
oThreeShow2.onclick = function () {
oMyAlert.show('我是样式一,我没有按钮,我会在1.5秒后消失', {
bgcolor: '#ccc',
opacity: 0.4,
showFn: function () {
oMyAlert.addClass('state1');
}
})
}
var i;
var arr = ['改变1', '改变2']
oThreeShow3.onclick = function () {
i = 0;
oMyAlert.show('我是样式二,我有按钮,点击关闭我才会消失', {
bgcolor: 'green',
opacity: 0.2,
aBtnTxt: ['改变文本', '样式一', '关闭'],
btn1: function () {
oMyAlert.changeMsg(arr[i++]);
i = i >= arr.length ? 0 : i;
},
btn2: function () {
oMyAlert.removeClass('state2');
oMyAlert.addClass('state1');
},
showFn: function () {
oMyAlert.addClass('state2');
}
})
}
</code></pre>
<button id="threeShow1">默认样式</button>
<button id="threeShow2">样式一</button>
<button id="threeShow3">样式二</button>
</li>
</ol>
</div>
<script src="./my_popup.js"></script>
<script src="./my_alert.js"></script>
<script>
window.onload = function () {
// 对话框1js
var oOneShow = document.getElementById('oneShow');
oOneShow.onclick = function () {
oMyAlert.show('我是谁?');
}
// 对话框2js
var oTwoShow = document.getElementById('twoShow');
oTwoShow.onclick = function () {
var iNum = 0;
oMyAlert.show('我是谁?', {
bgclose: false, // 是否可以点击背景关闭对话框(默认false不能)
bgcolor: '#999', // 背景颜色(默认transparent)
opacity: 0.2, // 背景透明度(默认0)
msgAlign: 'c', // 消息文本的对齐方式:l -> 左对齐;c -> 居中对齐(默认);r -> 右对齐
btnAlign: 'c', // 按钮的对齐方式:l -> 左对齐;c -> 居中对齐(默认);r -> 右对齐
aBtnTxt: ['确定', '取消', '关闭'], // 按钮的个数及其文本(默认无按钮)
btn1: function () { // btn1对应第一个按钮,btn+n对应第n个按钮的点击事件,如果不设置对应的事件,默认为调用close()关闭弹窗
if ( iNum == 0 ) {
oMyAlert.changeMsg('我是确定按钮,再点我就要消失了!');
iNum = 1;
} else {
oMyAlert.close();
}
},
btn2: function () {
iNum = 0;
oMyAlert.changeMsg('我是取消按钮,你点我呀!');
},
showFn: function () {
oMyAlert.addClass('state1');
}
});
}
// 对话框3js
var oThreeShow1 = document.getElementById('threeShow1');
var oThreeShow2 = document.getElementById('threeShow2');
var oThreeShow3 = document.getElementById('threeShow3');
oThreeShow1.onclick = function () {
oMyAlert.show('我是默认样式,我有按钮', {
bgcolor: '#999',
opacity: 0.2,
aBtnTxt: ['确定']
})
}
oThreeShow2.onclick = function () {
oMyAlert.show('我是样式一,我没有按钮,我会在1.5秒后消失', {
bgcolor: '#ccc',
opacity: 0.4,
showFn: function () {
oMyAlert.addClass('state1');
}
})
}
var i;
var arr = ['改变1', '改变2']
oThreeShow3.onclick = function () {
i = 0;
oMyAlert.show('我是样式二,我有按钮,点击关闭我才会消失', {
bgcolor: 'green',
opacity: 0.2,
aBtnTxt: ['改变文本', '样式一', '关闭'],
btn1: function () {
oMyAlert.changeMsg(arr[i++]);
i = i >= arr.length ? 0 : i;
},
btn2: function () {
oMyAlert.removeClass('state2');
oMyAlert.addClass('state1');
},
showFn: function () {
oMyAlert.addClass('state2');
}
})
}
}
</script>
</body>
</html>