开发者

jQuery SlidesJS keyboard navigation

开发者 https://www.devze.com 2023-03-29 07:25 出处:网络
My site uses SlidesJS for a photo slideshow. My question is, how can I use keyboard navigation? I\'开发者_如何转开发ve added this GitHub solution to my head tag (lines 94-116) but the keyboard\'s l

My site uses SlidesJS for a photo slideshow.

My question is, how can I use keyboard navigation?

I'开发者_如何转开发ve added this GitHub solution to my head tag (lines 94-116) but the keyboard's left & right arrow keys still aren't working.

How can I fix this?


I input the following code into the console window on chrome when on the SlidesJS site and it worked...

(function($){
    $(window).keyup(function(e){
        var key = e.which | e.keyCode;
        if(key === 37){ // 37 is left arrow
            $('a.prev').click();
        }
        else if(key === 39){ // 39 is right arrow
            $('a.next').click();
        }
    });
})(jQuery);

Edited for compatibility with pages that don't normally use $ for jQuery.


You can bind the keyup events to the window context and fire the click event on the next and prev buttons based on event.keyCode

jQuery(window).bind("keyup", function(e){
    if(e.keyCode === 37) {
        jQuery(".prev").click();
    } else if (e.keyCode === 39) {
        jQuery(".next").click(); 
    }
});

There should be some code in there to change the thumbs but that's the basic functionality off the top of my head.

0

精彩评论

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

关注公众号