如何将键盘箭头与jCarousel集成 - 使用Keynav jQuery插件?

Moh*_*zem 0 javascript jquery jcarousel

好的.我的想法是我有一个jCarousel列表,每个视图显示3个项目.我正在使用jQuery Keynav插件通过键盘箭头键导航元素.

现在,当我(通过键盘箭头)导航到实际隐藏在轮播中的项目时,jCarousel必须滑动到新视图.

有没有可能做到这一点?或者是否有任何其他插件-say Keynav插件 - 支持触发事件以及按键?

这是一个实例http://www.jsfiddle.net/F4GCc/5/ (You'll have to actually click in the "Result" pane for the keyboard arrow navigation to work.)

Jas*_*son 6

只需将文档绑定到keyup并检查以确保它是左箭头或右箭头:

$(document).on('keyup', function(e) {
    var key = e.which || e.keyChar || e.keyCode;
    if (key === 37)  {
      // left key
    } else if (key === 39) {
      // right key
    }
});
Run Code Online (Sandbox Code Playgroud)