I'm trying to add arrow key navigation to this image gallery.
It should work similar to this
var chosen = "";
$(document).keydown(function (e) { // 38-up, 40-down
if (e.keyCode == 40) {
if (chosen === "") {
chosen = 0;
} else if ((chosen + 1) < $('li.t').length) {
chosen++;
}
$('li.t').removeClass('selected');
$('li.t:eq(' + chosen + ')').addClass('selected');
$('li.t').click(this);
return false;
}
if (e.keyCode == 38) {
if (chosen === "") {
chosen = 0;
} else if (chosen > 0) {
chosen--;
}
$('li.t').removeClass('selected');
$('li.t:eq(' + chosen + ')').addClass('selected');
$('li.t').click(this);
return false;
}
});
…but I want each arrow key press to work like a click since it should load a page in the iframe and at the same time perform another click action (moving the yellow frame to the newly selected thumbnail) just like it does now when clicking.
Also it would be great if going down with the arrow keys could force scrolling to keep the selected thumbnail in view.
…if I got this to work I imagine the next issue I'd run into would be that I would lose focus on the main page and the arrow key navigation whenever something is clicked within the iframe. This is a negligible issue but if there was a simple solution for it I would like to use it.
Thanks.