开发者

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/.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜