1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to block the blocks from moving up?

Discussion in 'JavaScript' started by mark103, Sep 29, 2013.

  1. #1
    Hi guys,

    I have the list of rows with 7 blocks where the other blocks are hiding. I have 7 blocks which is showing from block 1 to block 7. When I press on the down arrow button of the keyboard, the blocks will moving up using 'rowheight' which it looks good to go, but there is a problem. When I press on the down arrow button until when the yellow block get on the end of the block, e.g.: block 11. When I press on the up arrow button quite few times, the blocks will move down without have any problem. When I try to press on the down button to get back to the block 11, the blocks supposed to stay where they are without moving up until the yellow block goes after the block 11 then move the blocks up, but the blocks will move up when I'm on the block 9. The same things it goes for other blocks.

    I think the problem are somewhere in this code:



    Code (Text):
    1.   if (event.keyCode == 38)
    2.   {  //up
    3.   if(current_col > 1 && current_row == 1)
    4.   {
    5.   var currentrowtop = $(".mainWrap div.row:first-child").css( "margin-top");  
    6.   var calcuatedrowtop = -(current_col*rowheight);
    7.   currentrowtop = parseInt(currentrowtop)-rowheight;
    8.  
    9.   if((currentrowtop - calcuatedrowtop) < rowheight)
    10.   {
    11.   currentrowtop = parseInt(currentrowtop)+rowheight;
    12.   currentrowtop = parseInt(currentrowtop)+rowheight;
    13.   var rowtop = currentrowtop+="px";
    14.   $(".mainWrap div.row:first-child").css( "margin-top", rowtop );  
    15.   }
    16.   current_col--;
    17.   }
    18.   }
    19.   else if (event.keyCode == 40)
    20.   {  //down
    21.   if(current_col < totalrowcount && current_row == 1)
    22.   {
    23.   if(current_col >= displayrowcount)
    24.   {
    25.   var currentrowtop = $(".mainWrap div.row:first-child").css( "margin-top");
    26.   currentrowtop = parseInt(currentrowtop)-rowheight;
    27.   var rowtop = currentrowtop+="px";
    28.   $(".mainWrap div.row:first-child").css( "margin-top", rowtop );
    29.   }
    30.   current_col++;
    31.   }
    32.   }


    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 to get on the block 9, if I press on the up arrow button few times and then the down arrow button to get back to the block 9 which it come after the block 8, the blocks will move up when I am on the middle of the blocks that I want to get to the block 9 without the blocks get moving. I want the blocks to stay where they are without get moving to allow me to get back to the block 9. The same things it goes for other blocks. I want the blocks to move up only when I'm after the end of the block beside the hiding blocks, e.g.: block 9. The block after the block 9 is the block 10 so I want to move them up when I'm on the block 10, block 11 and so on. I don't want the blocks to move up when I'm on the middle of the block even when I'm not on the end of the block.

    Does anyone know how I can block the blocks from moving up when I'm on the middle of the block to allow me to get on to each block until the end of the block, e.g block 11 then move the block 12 up and so on?

    Here's the jsfiddle if you need to take a look: http://jsfiddle.net/VZWNE/13/
    Last edited: Sep 29, 2013
    mark103, Sep 29, 2013 IP