Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Problem with keyboard control
09-26-2013, 11:59 PM #1
- Join Date
- Sep 2008
- Thanked 0 Times in 0 Posts
Problem with keyboard control
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:
if (event.keyCode == 40)
if(current_col < totalrowcount && current_row == 1)
if(current_col >= displayrowcount)
var currentrowtop = $(".mainWrap div.row:first-child").css( "margin-top");
currentrowtop = parseInt(currentrowtop)-rowheight;
var rowtop = currentrowtop+="px";
$(".mainWrap div.row:first-child").css( "margin-top", rowtop );
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
09-27-2013, 01:16 PM #2
- 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....