I'm using this script to toggle a class between a group of DIVs.
The keyboard nav works great, but if you mouse over a DIV, and then switch back to using your keyboard, you will notice the script does not remember the last DIV you moused over. It will continue to remember the last DIV you navigated to by keyboard.
Here is a JSFiddle demonstrating the problem: http://jsfiddle.net/bupGk/
What I am looking for is the correct equation that will calculate the index value for any given DIV on hover, with the class of column.
jQuery
var i = -1;
var all = $('.column');
$('.column').hover(function(){
$('.column').removeClass('scroll'),
$(this).addClass('scroll'),
i = $(this).eq() /*problem area*/
});
function traverse(ele) {
all.removeClass("scroll");
all.eq(ele).addClass("scroll");
}
$(document).keydown(function(e){
if (e.which == 37) {
e.preventDefault();
traverse( i = !i ? all.length - 1 : --i );
}
if (e.which == 39) {
e.preventDefault();
traverse( i = ++i % all.length );
}
});