-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.html
83 lines (73 loc) · 3.23 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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ventanas Emergentes Divertidas</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: transparent; /* Fondo transparente para mostrar la imagen */
}
</style>
</head>
<body>
<script>
const moveDistance = 5; // Distancia de movimiento por cada "tick" del intervalo
const popupSize = 100; // Tamaño de las ventanas para el cálculo de límites (100x100)
// Función para crear una nueva ventana emergente
function crearPopup() {
const popup = window.open("", "_blank", "width=100,height=100");
// Escribir contenido de la ventana emergente
popup.document.write(`
<html>
<head>
<title>Popup</title>
<style>
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: transparent; /* Fondo transparente */
}
img {
width: 100px; /* Tamaño de la imagen, manteniendo el cuadrado */
height: 100px; /* Tamaño de la imagen, manteniendo el cuadrado */
}
</style>
</head>
<body>
<img src="photos/Trollface.png" alt="Trollface" />
</body>
</html>
`);
// Mover la ventana emergente
moverPopup(popup);
// Manejar el evento de cierre de la ventana
popup.onbeforeunload = function() {
// No se abren más ventanas cuando se cierra
};
}
// Función para mover la ventana emergente
function moverPopup(popup) {
let x = Math.random() * (window.innerWidth - popupSize); // Posición aleatoria en X
let y = Math.random() * (window.innerHeight - popupSize); // Posición aleatoria en Y
popup.moveTo(x, y);
setInterval(() => {
// Calcular nuevas posiciones
x += Math.random() < 0.5 ? moveDistance : -moveDistance; // Mover a izquierda o derecha
y += Math.random() < 0.5 ? moveDistance : -moveDistance; // Mover a arriba o abajo
// Limitar la posición para que no se salga de la pantalla
x = Math.max(0, Math.min(x, window.innerWidth - popupSize));
y = Math.max(0, Math.min(y, window.innerHeight - popupSize));
popup.moveTo(x, y); // Mover la ventana emergente
}, 1000); // Mueve la ventana cada segundo
}
// Llama a crearPopup() solo una vez
crearPopup();
</script>
</body>
</html>