forked from jsskkj/Projeto-Pedido
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
37 lines (29 loc) · 1.29 KB
/
Copy pathscript.js
File metadata and controls
37 lines (29 loc) · 1.29 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
function moveButtonRandomly(button) {
const buttonWidth = button.offsetWidth;
const buttonHeight = button.offsetHeight;
// Obter as dimensões do body
const bodyRect = document.body.getBoundingClientRect();
// Ajustar minX e minY para a posição do canto superior esquerdo do body
const minX = bodyRect.left;
const minY = bodyRect.top;
// Ajustar maxX e maxY com base nas dimensões do body
const maxX = bodyRect.width - buttonWidth;
const maxY = bodyRect.height - buttonHeight;
// Calcular posições aleatórias dentro dos limites ajustados
const randomX = Math.random() * (maxX - minX) + minX;
const randomY = Math.random() * (maxY - minY) + minY;
// Aplicar as novas posições ao botão
button.style.position = "absolute";
button.style.left = `${randomX}px`;
button.style.top = `${randomY}px`;
}
document.getElementById("button2").addEventListener("mouseover", function () {
moveButtonRandomly(this);
});
document.getElementById("button2").addEventListener("click", function () {
moveButtonRandomly(this);
});
document.getElementById("button1").addEventListener("click", function () {
// Redirecionar para outra página
window.location.href = "aceito.html"; // Substitua 'outra_pagina.html' pelo URL da página desejada
});