0

No tengo muy claro cómo lograrlo. ¿Alguien me echa una mano?

var aleatori=1;
	
function si() {
	window.alert("Enhorabona");
}

function no() {
	var confirma = window.confirm("Estàs segur que no vols aprobar?");

	if (confirma == true){
		window.alert("Ens veiem a la recuperació");
	}
	else window.alert("Torna a intentar-ho");

}

//hacer una funcion por la cual si if está activado en tornar a intentar que no se active la funcion

function altraVegada(a) {
	aleatori=parseInt(Math.random() * 5);
	console.log(aleatori);
}

function swap (){
	 if(aleatori!=0){ 
		console.log(aleatori);
		console.log(document.getElementById("yes"));
		document.getElementById("no").style.position = "absolute";
		document.getElementById("yes").style.position = "absolute";
		document.getElementById("again").style.position = "absolute";
		document.getElementById("again").style.left = "3%";
		document.getElementById("no").style.left = "0.5%";
		document.getElementById("yes").style.left="11.3%";
	}
}
</br></br>
¿VOLS APROBAR?</br>
<input type="button" id="yes" value="Sí" onclick="si()" onmouseout="swap2()" onmouseover="swap()" >
<input type="button" id="again" value="Tornau a intentar" onclick= "altraVegada(yes)" >
<input type="button" id="no" value="No" onclick= "no()" >

3
  • Uncaught ReferenceError: swap2 is not defined el 22 mar. 2019 a las 2:30
  • Hola @TovarishAlex, como te indica otro usuario en un comentario, falta una función (swap2) para poder ver el problema. Por favor edita la pregunta para añadir un ejemplo mínimo verificable y completa el recorrido de bienvenida para aprender más sobre el sitio (y con ello ganar tu primera medalla).
    – Alvaro Montoro
    el 22 mar. 2019 a las 2:51
  • @AlvaroMontoro al parecer la función faltante swap2 sería el restore donde se trabó el 22 mar. 2019 a las 3:24

1 respuesta 1

0

usando unos divs temporales para hacer el swap dentro de un contenedor y con algo de css para que no haya saltos sale algo divertido:

var elAgain = document.getElementById("again");
var elSi = document.getElementById("si");
var elNo = document.getElementById("no");
var elContenedor = document.getElementById("contenedor");
var siTemp = document.createElement("div");
var noTemp = document.createElement("div");

function si() {
  console.log("si")
}

function no() {
  console.log("no")
}

function altraVegada(loQue) {
  console.log("va de nuevo", loQue)
}

function swap() {
  elContenedor.replaceChild(siTemp, elSi);
  elContenedor.replaceChild(noTemp, elNo);
  elContenedor.replaceChild(elNo, siTemp);
  elContenedor.replaceChild(elSi, noTemp);
}

function restore() {
  elContenedor.appendChild(elSi);
  elContenedor.appendChild(elAgain);
  elContenedor.appendChild(elNo);
}
#si,
#no {
  width: 40px;
}

input[type=button] {
  margin: 0 5px;
  display: inline-block;
  cursor: pointer;
}
</br>
</br>
¿VOLS APROBAR?</br>
<div id=contenedor>
  <input id=si
    type="button" value="Sí"
    onclick="si()" onmouseout="restore()" onmouseenter="swap()"><input id=again
    type="button" value="Tornau a intentar"
    onclick="altraVegada('yes')"><input id=no
    type="button" value="No" onclick="no()" onmouseout="restore()"
    onmouseenter="swap()">
</div>

1
  • Acabas de salvarme la vida, muchas gracias! el 27 mar. 2019 a las 11:41

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.