开发者

Trigger jCarouselLite on keypress

开发者 https://www.devze.com 2022-12-13 06:58 出处:网络
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 k

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

精彩评论

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

关注公众号