![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
06/09/2014, 00:40
|
| | Fecha de Ingreso: mayo-2010
Mensajes: 215
Antigüedad: 14 años, 9 meses Puntos: 4 | |
Respuesta: Problemas con este codigo Cita:
Iniciado por Alexis88 Podrías utilizar una variable comodín a la cual le asignarás un valor cuando se pulse la tecla y se lo cambiarás cuando acabe el efecto. Si se vuelve a pulsar la tecla, verificas el valor de la variable y de no haber cambiado, no ejecutas la función.
Código Javascript :
Ver originalanimar = true; function handleArrowKeys(evt) { evt = (evt) ? evt : ((window.event) ? event : null); if (evt) { switch (evt.keyCode) { case 39: if (animar){ a(); } break; case 40: if (animar){ b(); } break; } } } document.onkeyup = handleArrowKeys; function a(){ var posicionx=document.getElementById("block").offsetLeft; animar = false; $( "#block" ).animate({ left: posicionx+25, }, 750, function(){ animar = true; }); } function b(){ var posiciony=document.getElementById("block").offsetTop; $( "#block" ).animate({ top: posiciony+25, }, 750, function(){ animar = true; }); }
Saludos muchas gracias :D me sirvio |