Try adding an event listener for "keydown" then check the key codes.
Left is 37 and right is 39.
Based on the code you provided something like this could work.
PHP Code:
if( this.totalItems > 1 ) {
this.$navPrev = $( '<span class="gr-prev">prev</span>' ).on( 'click', $.proxy( this.navigate, this, 'prev' ) );
this.$navNext = $( '<span class="gr-next">next</span>' ).on( 'click', $.proxy( this.navigate, this, 'prev' ) );
this.$nav = $( '<nav/>' ).append( this.$navPrev, this.$navNext ).appendTo( $gallery );
document.onkeydown = function(e) {
e = e || window.event;
if(e.keyCode == "37") {
$.proxy(this.navigate, this, "prev");
} else if(e.keyCode == "39") {
$.proxy(this.navigate, this, "next");
}
};
}
Bookmarks