-
Notifications
You must be signed in to change notification settings - Fork 0
/
Popup.html
119 lines (106 loc) · 3.31 KB
/
Popup.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Customizable Popup</title>
<style>
.popup-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
opacity: 0;
visibility: hidden;
transition: opacity 0.3s ease, visibility 0.3s ease;
}
.popup-overlay.active {
opacity: 1;
visibility: visible;
}
.popup-content {
background-color: #fff;
padding: 2rem;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
max-width: 500px;
width: 90%;
max-height: 90vh;
overflow-y: auto;
position: relative;
transform: scale(0.7);
opacity: 0;
transition: transform 0.3s ease, opacity 0.3s ease;
}
.popup-overlay.active .popup-content {
transform: scale(1);
opacity: 1;
}
.popup-close {
position: absolute;
top: 10px;
right: 10px;
font-size: 1.5rem;
cursor: pointer;
background: none;
border: none;
color: #333;
}
.popup-close:hover {
color: #000;
}
/* Demo styles */
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
#openPopup {
padding: 10px 20px;
font-size: 1rem;
cursor: pointer;
}
</style>
</head>
<body>
<button id="openPopup">Open Popup</button>
<div id="popupOverlay" class="popup-overlay">
<div class="popup-content">
<button class="popup-close" id="closePopup">×</button>
<h2>Popup Title</h2>
<p>This is the content of the popup. You can put any HTML content here, including forms, images, or text.</p>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const openPopup = document.getElementById('openPopup');
const closePopup = document.getElementById('closePopup');
const popupOverlay = document.getElementById('popupOverlay');
function togglePopup() {
popupOverlay.classList.toggle('active');
}
openPopup.addEventListener('click', togglePopup);
closePopup.addEventListener('click', togglePopup);
popupOverlay.addEventListener('click', function(e) {
if (e.target === popupOverlay) {
togglePopup();
}
});
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && popupOverlay.classList.contains('active')) {
togglePopup();
}
});
});
</script>
</body>
</html>