Show some DIV layer part by part

Discussion in 'JavaScript' started by parasolx, Jun 19, 2008.

  1. #1
    ok.. here is what i wanna to do.. I have about 4 div layer... and wanna to show that 4 div layer one by one after some one click on button.

    also, if possible, the delay between one layer to one layer showing is randomize between 5 to 9 second.
     
    parasolx, Jun 19, 2008 IP
  2. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #2
    I cannot write the code for you as I am not surfing from my cosy home but from an cafe. But I will give you leads.

    1. Create and array of all DIVs using the getEementsByTagName() function.
    
    alldiv=document.getElementsByTagName("div");
    
    Code (markup):
    2. Calculate the length of the array.
    
    no=alldiv.length;
    
    Code (markup):
    3. Now, at random pick any value from the array using the
    
    randomno=Math.floor(Math.random()*no);
    //no is the number of elements in the array initially
    
    Code (markup):
    4. Establish reference to the randomly selected DIV by using
    
    randomdiv=alldiv[randomno];
    
    Code (markup):
    5. Now manipulate the display of that DIV
    
    randomdiv.style.display="inline";
    
    Code (markup):
    6. Delete this random DIV from our array of divs which we created in step 1.
    
    delete alldiv[randomno];
    
    Code (markup):
    7. Repeat steps 2 to 6.

    Now put these in a function such as showRandomDiv() and call that function at preset intervals with setInterval() function. Remember to clear the interval when there are no items left in the alldiv array(because that means that all divs are now made visible).

    I have not tested this code because I am not at my home place right now.

    Enjoy, also you may need little modifications particularly in step 1 and step 4. You may consider using IDs and getElementById() functions there.
     
    rohan_shenoy, Jun 19, 2008 IP
  3. parasolx

    parasolx Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for your guide... but i'm freshy in javascript. Could somebody write the code in proper... where to put this script, either it could be put in BODY or must put in the HEAD. Plz... help me...

    Here is details what i wanna to do:
    1. Some one click the button
    2. <div id="layer1"> show ... delay (randomize between 5 - 9)
    3. <div id="layer2"> show ... delay (randomize between 5 - 9)
    4. ...
    5. ...
     
    parasolx, Jun 19, 2008 IP