Using arrow keys with jQuery scrollTo

前端 未结 3 821
忘掉有多难
忘掉有多难 2020-12-11 09:57

I have successfully implemented the scrollTo jQuery plugin which scrolls to the next div with the class \"new\" when a link is clicked. However, I would also like to be able

3条回答
  •  被撕碎了的回忆
    2020-12-11 10:26

    You need to capture the keypress event and decide which keycode was pressed

    $(document).keypress(function(e) {
        switch(e.keyCode) { 
            case 37:
                //left arrow pressed
            break;
            case 39:
                //right arrow pressed
            break;
        }
    });
    

提交回复
热议问题