I want to give my content slider the ability to respond to keypress (LEFT ARROW key and RIGHT ARROW key) feature. I have read about some conflicts between several browsers and operation systems.
The user can navigate the content while he is on the global website (body).
Pseudo Code:
ON Global Document
IF Key Press LEFT ARROW
THEN animate #showroom css 'left' -980px
IF Key Press RIGHT ARROW
THEN animate #showroom css 'left' +980px
I need a solution without any crossover (Browsers, OSs) conflicts.
$("body").keydown(function(e) {
if(e.keyCode == 37) { // left
$("#showroom").animate({
left: "-=980"
});
}
else if(e.keyCode == 39) { // right
$("#showroom").animate({
left: "+=980"
});
}
});
$("body").keydown(function(e){
// left arrow
if ((e.keyCode || e.which) == 37)
{
// do something
}
// right arrow
if ((e.keyCode || e.which) == 39)
{
// do something
}
});
This works fine for me :
$(document).keypress(function (e){
if(e.keyCode == 37) // left arrow
{
// your action here, for example
$('#buttonPrevious').click();
}
else if(e.keyCode == 39) // right arrow
{
// your action here, for example
$('#buttonNext').click();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With