views:

141

answers:

1

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

+1  A: 

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
  }
});
Mark Ursino
Worked great, thanks Mark! I wasn't using left and right buttons, so I appended them to my navigation div using jQuery along with CSS style of display: none. Then I just used those hidden buttons in my initialization along with the trigger you suggested.
Jared