0

I have this javascript function which does pagination to my image slider. I also would like to add keyboard arrows navigation (left and right) based on the existing javascript code. I am not much familiar with javascript.

here is my javascript code

pageSize = 1;

showPage = function(page) {
    $(".comix").hide();
    $(".comix").each(function(n) {
        if (n >= pageSize * (page - 1) && n < pageSize * page)
            $(this).show();

    });        
}

showPage(1);

$("#pagin li a").click(function() {
    $("#pagin li a").removeClass("current");
    $(this).addClass("current");
                $('html, body').animate({scrollTop: $("#wrapper").offset().top}, 1000);

    showPage(parseInt($(this).text())) 
});

    $('#pagin li').each(function(i) {
    if ( i === 1 ) {
       $(this).addClass('current');
    }
});

Here is my jsFiddle

I have no idea how to approach it. Any help would be highly appreciated.

Venkateshwaran Selvaraj
  • 1,745
  • 8
  • 30
  • 60

1 Answers1

0

You just catch events for left and right keys

$(document).keydown(function(e){
    if (e.keyCode == 37) { 
       alert( "left pressed" );
       return false;
    }
    elseif (e.keyCode == 39) { 
       alert( "right pressed" );
       return false;
    }
});

Source: https://stackoverflow.com/a/1402733/73010

Community
  • 1
  • 1
FrEaKmAn
  • 1,785
  • 1
  • 21
  • 47