I want to use keystrokes , in my website. But the problem is, when you press the right arrowkey in firefox the page jumps a little bit to the right. I don't want that. This is my code:
$(document).bind('keystrokes', {
开发者_开发问答 keys: ['arrow right']
}, function(event){
goRight();
event.preventDefault();
// and / or
event.stopPropagation();
return false;
});
But this doesn't work. Am I able to override the firefox settings to go to the right when the right arrowkey is pressed? IE doesn't has this, so it works perfectly there. Or is it a browser issue, and there is no solution to this (except making my page small enough for the window).
I should say that my page is wider than the screen, and the body has overflow:hidden;
.
Thanks in advance!
Guess: add event.preventDefault()
along with return false.
Edit: nope that won't work, and I don't know about keystrokes, but this will work:
$(document).keydown(function(event) {
if (event.keyCode == 39) {
event.preventDefault();
return false;
}
});
Have you tried to use :
event.preventDefault();
// and / or
event.stopPropagation();
?
精彩评论