Reputation: 883
I want to add some hotkeys to my webpage, such as using j/k as page up/down, as this web page did: http://www.theatlantic.com/infocus/2011/07/tour-de-france-2011---part-1/100105/
What's the easiest/cleanest way to do that?
Upvotes: 2
Views: 295
Reputation: 211
I leave a solution that doesn't require jQuery, in case useful:
document.addEventListener('keydown', function(event) {
if (event.key === 'j') {
window.scrollBy(0, 80); // Scroll down by 80 pixels
}
if (event.key === 'k') {
window.scrollBy(0, -80); // Scroll up by 80 pixels
}
});
Upvotes: 0