Answer the question
In order to leave comments, you need to log in
How to set up an event when a button is pressed on the keyboard??
Hello, I am writing a presentation in the form of a slider in full screen and decided to set up an event to change the slide to arrows - left and right.
How can this be done in javascript and jquery?
And there is 1 more question, what plugin can I install for Sublime(2) to highlight js and jquery syntax??
Answer the question
In order to leave comments, you need to log in
Like this: jsfiddle.net/7o9maLLs/1
+ you can add more buttons besides the arrows
$(document).on('keyup', function (event) {
var key = event.which;
switch (key) {
case 8: // backspace
case 33: // Page Up
case 37: // <-
console.log("Назад");
break;
case 32: // space
case 34: // Page Down
case 39: // ->
console.log("Вперед");
break;
}
});
$(document).keydown(function(e) {
switch(e.which) {
case 37: // left
break;
case 38: // up
break;
case 39: // right
break;
case 40: // down
break;
default: return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question