-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction_start.html
77 lines (64 loc) · 1.98 KB
/
function_start.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Function start</title>
<style>
.msgBox {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
width: 242px;
background: #eee;
}
.msgBox p {
line-height: 1.5;
padding: 10px 20px;
color: #333;
padding-left: 82px;
background-color: 25px center;
background-repeat: no-repeat;
}
.msgBox button {
background: none;
border: none;
position: absolute;
top: 0;
right: 0;
font-size: 1.1rem;
color: #aaa;
}
</style>
</head>
<body>
<button>Display message box</button>
<script>
const btn = document.querySelector('button');
// btn.addEventListener('click', displayMessage('Your inbox is almost full - delete some emails', 'warning'));
btn.addEventListener('click', displayMessage('Brian: Hi there, how are you today?', 'chat'));
function displayMessage(msgText, msgType) {
const html = document.querySelector('html');
const panel = document.createElement('div');
panel.setAttribute('class','msgBox');
html.appendChild(panel);
const msg = document.createElement('p');
msg.textContent = msgText;
panel.appendChild(msg);
const closeBtn = document.createElement('button');
closeBtn.textContent = 'x';
panel.appendChild(closeBtn);
closeBtn.addEventListener('click', () => panel.parentNode.removeChild(panel));
if (msgType === 'warning') {
msg.style.backgroundImage = 'url(icons/warning.png)';
panel.style.backgroundColor = 'red';
} else if (msgType === 'chat') {
msg.style.backgroundImage = 'url(icons/chat.png)';
panel.style.backgroundColor = 'aqua';
} else {
msg.style.paddingLeft = '20px';
}
};
</script>
</body>
</html>