2011-12-08 30 views
1

如何使用jquery keydown函数分别滚动两个列表?如何使用jquery keydown函数分别滚动两个列表?

  $(document.keydown(function(e1) 
     { 
      // ul list B - insert data 

      if(e.which == leftArrowKey1) 
      { 
        // scroll left 

      }else if(e.which == rightArrowKey1 || e.which == spacebarKey1) 

        // scroll right            
      } 
     }); 

     $(document.keydown(function(e2) 
     { 
       // ul list B - insert data 

      if(e2.which == leftArrowKey2) 
      { 
       // scroll left 

      }else if(e2.which == rightArrowKey2 || e2.which == spacebarKey2) 

       // scroll right      
      } 
    }); 

在所述文档的加载,我可以在文档的相同加载内滚动或者列表B或A而不是两者。换句话说,如果我第一次滚动列表A,我不能滚动列表B.我只能在点击重载按钮后滚动列表B.

回答

0

div或某些父元素的列表? 如果是这样,只需将​​事件放在父元素上,而不是document

$('.list').keydown(function(e) { // for each list trap the keydown event 
    var list = $(this);    // store the active list object 
    if (e.which == leftArrowKey) { 
      e.PreventDefault(); 
      // scroll the list element left 
    } else if(e.which == rightArrowKey || e.which == spacebarKey) 
      e.PreventDefault(); 
      // scroll the list element right 
    } 
}); 
+0

谢谢TerryR,但这不起作用。只有$(document).keydown似乎工作。 –

+0

要回答你的问题,我有一个div的列表 –

+0

将你的HTML代码粘贴到你的问题中。 – Terry

相关问题