Advertisement
Guest User

Jquery script keyboard navigation

a guest
Jun 16th, 2010
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).keydown( function(event) {
  2.  
  3.         if($("#content tr.sel").length >= 1) {
  4.             var id  = $("#content tr.sel").attr("id");
  5.         } else if($("#content tr:first").length >=1 ) {
  6.             $("#content").scrollTo(0);
  7.             $("#content tr:first").addClass("sel");
  8.         }
  9.        
  10.         key = event.keyCode;
  11.  
  12.         switch(key) {
  13.  
  14.             case 40:
  15.                     if($("#"+id).next().length > 0 ) {
  16.                    
  17.                         var position = $("#"+id).position();
  18.                        
  19.                         $("#"+id).removeClass("sel use");
  20.                         $("#"+id).next().addClass("sel");
  21.                        
  22.                         if(position.top > $("#content").outerHeight(true)/2) {
  23.                             keyNav = true;
  24.                             $("#content").scrollTo('+='+$("#"+id).outerHeight(true)+'px',{ 'onAfter': function() { keyNav=false; } });
  25.                         }
  26.                     }
  27.                    
  28.                 break;
  29.             case 38:
  30.                     if($("#"+id).prev().length > 0 ) {
  31.                    
  32.                         var position = $("#"+id).position();
  33.                        
  34.                         $("#"+id).removeClass("sel use");
  35.                         $("#"+id).prev().addClass("sel");
  36.                          
  37.                         if(position.top < $("#content").outerHeight(true)/2) {
  38.                             keyNav = true;     
  39.                             $("#content").scrollTo('-='+$("#"+id).outerHeight(true)+'px',{  'onAfter': function() { keyNav=false; } });
  40.                         }
  41.                     }
  42.  
  43.                 break;
  44.         }
  45.     }
  46.  
  47. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement