You cannot emulate the hang state perfectly .. there is no way out of adding a "real" class with the same style:
.display_box_hover, .display_box:hover { background:#3b5998; color:#FFFFFF; }
Now this code will "move" the elements:
window.displayBoxIndex = -1; $("#search").keyup(function(e) { if (e.keyCode == 40) { Navigate(1); } if(e.keyCode==38) { Navigate(-1); } }); var Navigate = function(diff) { displayBoxIndex += diff; var oBoxCollection = $(".display_box"); if (displayBoxIndex >= oBoxCollection.length) displayBoxIndex = 0; if (displayBoxIndex < 0) displayBoxIndex = oBoxCollection.length - 1; var cssClass = "display_box_hover"; oBoxCollection.removeClass(cssClass).eq(displayBoxIndex).addClass(cssClass); }
This will “remember” the index of the last “selected” element and switch to the next or previous element using the eq() function and adding a class on top of that selected element.
Updated jsFiddle .
Shadow wizard
source share