-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
74 lines (63 loc) · 2.24 KB
/
main.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
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
// var modal = document.getElementById("myModal");
// var btn = document.getElementById("openModal");
// var span = document.getElementById("closeModal");
// btn.onclick = function() {
// console.log('pruebas');
// modal.style.display = "block";
// modal.style.height = "100vh";
// modal.style.position = "relative";
// }
// span.onclick = function() {
// modal.style.display = "none";
// }
// window.onclick = function(event) {
// if (event.target == modal) {
// modal.style.display = "none";
// }
// }
// // Cerrar el modal con la tecla "Esc"
// document.addEventListener('keydown', function(event) {
// if (event.key === "Escape" && modal.style.display == "block") {
// modal.style.display = "none";
// }
// });
var modal = document.getElementById("myModal");
var btns = document.querySelectorAll(".openModal"); // Obtiene todos los botones con la clase "openModal"
var span = document.getElementById("closeModal");
var iframe = document.getElementById("iframeModal");
// Abre el modal y establece el contenido del iframe
btns.forEach(function (btn) {
btn.addEventListener('click', function () {
var link = this.getAttribute('data-link'); // Obtiene el atributo data-link del botón
iframe.src = link; // Establece la URL del iframe
// Obtiene la posición del botón
const rect = btn.getBoundingClientRect();
const top = rect.top + window.scrollY;
const left = rect.left + window.scrollX;
// Establece la posición del modal encima del botón
modal.style.display = "block";
modal.style.top = top + "px";
modal.style.left = "20%";
modal.style.height = "100vh";
modal.style.width = "auto";
});
});
// Cierra el modal
span.onclick = function() {
modal.style.display = "none";
iframe.src = ""; // Limpiar el contenido del iframe
}
// Cierra el modal si se hace clic fuera de él
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
iframe.src = ""; // Limpiar el contenido del iframe
}
}
// Cierra el modal con la tecla "Esc"
document.addEventListener('keydown', function(event) {
if (event.key === "Escape" && modal.style.display == "block") {
modal.style.display = "none";
iframe.src = ""; // Limpiar el contenido del iframe
}
});