-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen_modal.html
More file actions
59 lines (52 loc) · 1.47 KB
/
open_modal.html
File metadata and controls
59 lines (52 loc) · 1.47 KB
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
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Open modal on button click</title>
</head>
<body>
<style>
.hidden {
display: none;
}
#overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 1;
}
.box {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 30px;
background: antiquewhite;
border-radius: 5px;
z-index: 2;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}
</style>
<button id="clickbtn">Open Modal</button>
<div id="overlay" class="hidden"></div>
<div id="one" class="box hidden">
DIV ONE CONTENT
<button id="closebtn">Close</button>
</div>
<script>
const openBtn = document.getElementById("clickbtn");
const closeBtn = document.getElementById("closebtn");
const modal = document.getElementById("one");
const overlay = document.getElementById("overlay");
openBtn.addEventListener("click", () => {
modal.classList.remove("hidden");
overlay.classList.remove("hidden");
});
closeBtn.addEventListener("click", () => {
modal.classList.add("hidden");
overlay.classList.add("hidden");
});
</script>
</body>
</html>