开发者

Trigger jCarouselLite on keypress

I'm using jCarouselLite to create a navigation element somewhat similar to the tabbed navigation used on Panic's Coda site,开发者_如何学JAVA but I'd like to trigger the left and right scroll on a keypress. Can this be done without modifying the jCarouselLite code? Thanks!


Using the default settings, the buttons contain the classes .prev and .next so why not try to trigger clicks on them?

function myFunction() {
  $(".prev").trigger("click");
}

If you pass in your own classes or IDs for the buttons in the options, bind to them instead.

This example will fire when you hit the left and right keyboard keys:

$(document).keyup(function(e) {
  var code = (e.keyCode ? e.keyCode : e.which);

  switch(code) {
    case 37: $(".prev").trigger("click"); break; // left
    case 39: $(".next").trigger("click"); break; // right
  }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜