-
Notifications
You must be signed in to change notification settings - Fork 6
/
popup.js
40 lines (33 loc) · 1.27 KB
/
popup.js
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
document.addEventListener("DOMContentLoaded", function() {
const popup = document.getElementById("popup");
const popupContent = document.querySelector(".popup-content");
const closeBtn = document.querySelector(".close-btn");
if (popup && popupContent && closeBtn) {
// Show the popup with animation
popup.style.display = "flex";
popupContent.style.animation = "slideUp 0.5s forwards";
function closePopup() {
// Slide up out animation
popupContent.style.animation = "slideUpOut 0.5s forwards";
// Hide the popup after the animation ends
setTimeout(function() {
popup.style.display = "none";
}, 500); // Match this duration with the animation duration
}
closeBtn.addEventListener("click", function() {
closePopup();
});
window.addEventListener("click", function(event) {
if (event.target === popup) {
closePopup();
}
});
document.addEventListener("keydown", function(event) {
if (event.key === "Escape") {
closePopup();
}
});
} else {
console.error("One or more required elements not found.");
}
});