-
Notifications
You must be signed in to change notification settings - Fork 0
/
modalka.html
106 lines (97 loc) · 2.77 KB
/
modalka.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<style>
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.content {
width: 400px;
background: #444;
border-radius: 5px;
padding: 10px;
color: #fff;
margin: 0;
}
.close {
color: #fff;
position: absolute;
right: -5px;
top: -10px;
background: #d00;
border-radius: 50%;
width: 20px;
height: 20px;
line-height: 20px;
text-align: center;
text-decoration: none;
}
.overlay {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(00, 00, 00, .2);
z-index: 10000;
}
.btn {
background: palevioletred;
border: none;
color: white;
padding: 15px 20px;
border-radius: 3px;
font-size: 20px;
}
.modal-container {
position: relative;
}
</style>
<div class="container">
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Rerum minima officia provident distinctio quod mollitia alias. Natus repellat quae officiis neque, soluta quisquam quidem illum quos rem dolore numquam iure. Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dignissimos deserunt ex quia quidem recusandae hic facere vel distinctio vero ullam rerum harum, enim minima quo. Enim praesentium aliquam porro molestias.</p>
<button class="btn" id="open">открыть</button>
</div>
<script>
const openBtn = document.querySelector("#open");
const body = document.body;
openBtn.addEventListener('click', e => {
const overlayElem = document.createElement("div");
overlayElem.classList.add("overlay");
overlayElem.addEventListener('click', e => {
if (e.target == overlayElem) {
closeBtn.click();
}
});
const containerElem = document.createElement("div");
containerElem.classList.add("modal-container");
const contentElem = document.createElement("div");
contentElem.classList.add("content");
contentElem.innerHTML = "Hello, <b>world!<b>";
const closeBtn = document.createElement("a");
closeBtn.classList.add("close");
closeBtn.innerHTML = "x";
closeBtn.href = "#";
closeBtn.addEventListener('click', e => {
e.preventDefault();
body.removeChild(overlayElem);
});
overlayElem.appendChild(containerElem);
containerElem.appendChild(closeBtn);
containerElem.appendChild(contentElem);
body.appendChild(overlayElem);
});
</script>
</body>
</html>