2011-12-08 36 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

相關問題