Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Thanked 0 Times in 0 Posts

    Problem with keyboard control

    Hi guys,

    I'm working on the div class of blocks to control them using the keyboard up and down arrow buttons. I have the list of blocks where 7 of them are showing while the other blocks are hiding. I have text of blocks from block 1 to block 17. When I press on the down arrow button from block 1 to block 17, the blocks will move up using 'rowheight' which it looks good to go, but there is a problem. When I press on the up arrow button and the down arrow button after the block 7, the blocks supposed to stay where they are but it will move up when the yellow block is on the block 8, block 9, block 10, block 11, block 12, block 13, block 14, block 15, block 16 and block 17.

    I think the problem are somewhere in this code:

    PHP Code:
      if (event.keyCode == 40)
    if(current_col totalrowcount && current_row == 1)
    current_col >= displayrowcount)
    currentrowtop = $(".mainWrap div.row:first-child").css"margin-top");
    currentrowtop parseInt(currentrowtop)-rowheight;
    rowtop currentrowtop+="px";
    ".mainWrap div.row:first-child").css"margin-top"rowtop );
    In this case, when I press on the down arrow button from block 1 to block 7 and if I press on the up arrow button, the blocks will not move up where it stays on. When I press on the down arrow button after the block 7, if I press on the up arrow button and then the down arrow button, the blocks will move up. The same things that goes for other blocks. I want the blocks to move up only when I'm after the end of the block where the blocks are hiding, e.g.: I'm on the block 7 while the other blocks after the block 7 are hiding so I can move them up. I don't want to move the blocks up when I'm not the end of the block.

    Does anyone know how I can block the blocks from move up when I'm not after the end of the block while the other blocks are hiding?

    Here's my example site if you need to take a look: http://testbox.elementfx.com/blocks.php

  2. AdSlot6
  3. #2
    Senior Coder
    Join Date
    Feb 2009
    Ilkley, West Yorkshire, UK
    Thanked 727 Times in 721 Posts
    Hmm, not sure I entirely follow your code (current_col presumably refers to the current row?), but it seems like you need another piece of info to decide whether to scroll or not, which is whether the block that's moved to is already visible or not.

    You could write something to work this out each time, but I think I'd tackle this by assigning a 'visible' class to each visible block, and amending this after each scroll event. Then when a keypress indicates a move to a new block you can just check whether that block is already visible (in which case no scroll needed) or whether it's not.

    Don't know if that helps....
    Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
    Read Steve Krug's book Don't Make Me Think - essential reading on web usability
    I don't recommend much, but I do recommend Clook for UK web hosting


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts