Loop through keypress Jquery (case : 1; etc..) -


i have problem how maintain/continue loop if key pressed. figured animate page case 1 / case 2 / case 3 , case 4 know how continue loop if key pressed again (and again...). read loop here can't figure out.

thanks in advance, here code :

var counter = 0;  $(document).bind('keydown', function(e) {     if(e.which == 37 || e.which == 39) {         counter++;         switch(counter) {             case 1:                 $('#maikeximu,#dossier').stop()                     .animate({                         height: "toggle",                     }, 1200, function() {                         $('html,body').animate({                             scrolltop: $("#maikeximu").next().offset().top                         }, 1000);                     });                 break;             case 2:                 $("#gal,#dossier, #viz").stop()                     .animate({                         height: "toggle",                     }, 1200, function() {                         $('html,body').animate({                             scrolltop: $("#gal").next().offset().top                         }, 1000);                      });                 break;             case 3:                 $('#viz,#dossier').stop()                     .animate({                         height: "toggle",                     }, 1200, function() {                         $('html,body').animate({                             scrolltop: $("#dossier").next().offset().top                         }, 1000);                     });                 break;             case 4:                 $('#maikeximu, #gal,#dossier').stop()                     .animate({                         height: "toggle",                     }, 1200, function() {                         $('html,body').animate({                             scrolltop: $("#maikeximu").offset().top                         }, 0);                     });                 break;                 counter = 0;                 return;         }     };  }); 

i hope learn more loops (a big problem me) :)

the lines

            counter = 0;             return; 

are within switch statement, not within particular case defined there, means they're never getting executed. prevents counter resetting, what's stopping animation.

place them before break ending fourth case, thus:

                /* they're here */                 counter = 0;                 return;             break;             /* here */     } 

and should see work more you're expecting.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -