Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-09-2009, 05:23 AM   PM User | #1
Apothem
Regular Coder

 
Apothem's Avatar
 
Join Date: Mar 2008
Posts: 380
Thanks: 36
Thanked 25 Times in 25 Posts
Apothem is an unknown quantity at this point
Using $(window).keydown but disabling the key pressed and error

Code:
		$(window).keydown(function(e){
			if( e.keyCode == 9 ) { // 9 = Tab
				$('*').animate({scrollTop: ($(window).scrollTop() + 500)+'px'}, 1000);
				return false;
			}
		});
Every time I press my tab button, it would do the event BUT it would stick to its position and refrain from moving. In other words, I click tab. It would move the page down by 500 pixels. I try to scroll down, but I can't (I'm using FF 3.0.8)

What's wrong?

ALSO when I click the tab button, the tab is still activated even after I returned false. What's wrong with that as well?

Last edited by Apothem; 04-09-2009 at 05:23 PM..
Apothem is offline   Reply With Quote
Old 04-09-2009, 07:53 AM   PM User | #2
Iszak
Regular Coder

 
Iszak's Avatar
 
Join Date: Jun 2007
Location: Perth, Western Australia
Posts: 332
Thanks: 2
Thanked 58 Times in 57 Posts
Iszak is an unknown quantity at this point
I don't know if using the universal selector is appropriate, but I managed to make up an alternative with the following code.
Code:
$('html').keydown(function(event){
  if (event.keyCode === 9)
  {
    $('html').animate({
      scrollTop: $('html').scrollTop() + 500 + 'px'
    });

    return false;
  }
});
Preview: http://pastebin.me/49dd9b1b4aa77

Also, just an idea, maybe make it so key + tab will scroll back to the top or when you're at the bottom and press the tab again, it'll scroll to the top.

Goodluck.

Edit: I've found that it doesn't work for Safari and Google Chrome (webkit) so here's the fix for it.
Code:
$(document).keydown(function(event){
  if (event.keyCode === 9)
  {
    $('html, body').animate({
      scrollTop: $(document).scrollTop() + 500 + 'px'
    });

    return false;
  }
});

Last edited by Iszak; 04-09-2009 at 10:11 AM..
Iszak is offline   Reply With Quote
Users who have thanked Iszak for this post:
Apothem (04-09-2009)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:36 AM.


Advertisement
Log in to turn off these ads.