31 lines
876 B
HTML
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> |