Ver Mensaje Individual
  #3 (permalink)  
Antiguo 06/09/2014, 00:40
helion
 
Fecha de Ingreso: mayo-2010
Mensajes: 215
Antigüedad: 14 años
Puntos: 4
Respuesta: Problemas con este codigo

Cita:
Iniciado por Alexis88 Ver Mensaje
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 original
  1. animar = true;
  2.  
  3. function handleArrowKeys(evt) {
  4.     evt = (evt) ? evt : ((window.event) ? event : null);
  5.     if (evt) {
  6.         switch (evt.keyCode) {
  7.             case 39:  
  8.                 if (animar){
  9.                     a();    
  10.                 }
  11.             break;
  12.             case 40:
  13.                 if (animar){
  14.                     b();    
  15.                 }
  16.             break;    
  17.         }
  18.     }
  19. }  
  20.  
  21. document.onkeyup = handleArrowKeys;
  22.  
  23. function a(){
  24.     var posicionx=document.getElementById("block").offsetLeft;
  25.     animar = false;
  26.    
  27.     $( "#block" ).animate({
  28.         left: posicionx+25,
  29.     }, 750, function(){
  30.         animar = true;
  31.     });
  32. }
  33.      
  34. function b(){
  35.     var posiciony=document.getElementById("block").offsetTop;
  36.      
  37.     $( "#block" ).animate({
  38.         top: posiciony+25,
  39.     }, 750, function(){
  40.         animar = true;
  41.     });
  42. }

Saludos
muchas gracias :D me sirvio