How handle "left" and "right" key on Prototype?
I need manipulate "left" and "right" key on prototype, something li开发者_如何学Pythonke http://mangastream.com/
As simple as:
$(document).observe('keydown', function (e) {
switch (e.keyCode) {
case Event.KEY_LEFT:
e.stop(); // prevent the default action, like horizontal scroll
window.location = '/read/prev';
break;
case Event.KEY_RIGHT:
e.stop();
window.location = '/read/next';
break;
}
});
http://jsfiddle.net/pMts6/
Event.KEY_LEFT
and Event.KEY_RIGHT
are their handy constants for the numerical codes of the corresponding keys.
Read up on Prototype events at http://api.prototypejs.org/dom/Event/.
精彩评论