开发者

How handle "left" and "right" key on Prototype?

开发者 https://www.devze.com 2023-03-19 14:20 出处:网络
I need manipulate \"left\" and \"right\" key on prototype, something li开发者_如何学Pythonke http://mangastream.com/As simple as:

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

精彩评论

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