IFCD0210/Practicas/Practicas JS/boton escapista/index.html
Marcos Lopez ad40171fb4 Dia 32
2024-01-22 13:46:08 +01:00

31 lines
876 B
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mover botón con JavaScript</title>
<style>
#moverBoton {
position: absolute;
top: 50px;
left: 50px;
transition: top 0.3s ease, left 0.3s ease;
}
</style>
</head>
<body>
<button id="moverBoton" onmouseover="moverBoton()">Pulsame</button>
<script>
function moverBoton() {
var boton = document.getElementById('moverBoton');
var nuevaPosicionTop = Math.random() * (window.innerHeight - boton.clientHeight);
var nuevaPosicionLeft = Math.random() * (window.innerWidth - boton.clientWidth);
boton.style.top = nuevaPosicionTop + 'px';
boton.style.left = nuevaPosicionLeft + 'px';
}
</script>
</body>
</html>