tags:

views:

423

answers:

4

I have a problem that I'm not even sure what to search for in order to fix. When I press the spacebar my entire page moves down (I don't want this to happen). My BODY tag is styled to overflow:hidden (if that has anything to do with it) so it won't have any scrollbars. I'm usually pretty good at executing the preliminary troubleshooting techniques but in this case I don't even know where to start....please help.

Additional Info:

I am using jQuery_v1.4.2

+6  A: 

Unless you eat the keypress this is the expected behavior in most browsers. I use it all the time and I get extremely annoyed when it doesn't work in a page.

But if you want to eat the key...

window.onkeydown = function(e) { 
  return !(e.keyCode == 32);
};
Josh Einstein
+2  A: 

The behavior you describe is pretty standard. If you are creating content that is taller than the page, why are you hiding some of it?

Robusto
+3  A: 

It's not enough to just hide the overflow; you actually have to make it not overflow. Even if you could disable the behavior (eating the keystroke, putting focus inside some other container), the user might still be able to scroll via the keyboard, by drag-selecting text on the page, holding down the middle mouse button, etc... It's really up to their browser, and so long as the content is still technically visible, they'll probably have some way to scroll it into view.

Time to re-think your layout.

Shog9
A: 

I have a site where there is a dynamic menu and it is z-indexed. There is a arcade on that site and many of the flash games uses spacebar and arrow keys to play. If i put the flash in wmode=opaque or transparent I get a bug with internet explorer. In Firefox when you clic the games you give them focus and the page wont scroll (just like normal wmode(window)). But internet explorer will scroll the page putting the game out of sight !!! And of coarse using wmode=window will put the menu behind the flash, making it unusable. I need to disable up/cown arrows and spacebar scroll in the arcade ! Just for that. else I agree that changing default behavior is bad but i can understand that some situations are more like wich is the behavior the user will expect to be normal... Game motion or page scroll etc...

Stony