Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3

Thread: Div Layer Swap

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Posts
    2
    Member #
    15558
    I am trying to create a layer swap using div's. Something similar to what they have here at http://www.ign.com. Scroll down a bit to latest updates. Basically, div's occupying the same space that appear when a button is clicked. Any help would be appreciated.

  2.  

  3. #2
    Senior Member paintingtheweb's Avatar
    Join Date
    Jul 2007
    Location
    Las Vegas
    Posts
    128
    Member #
    15503
    What you're looking for I believe is a javascript style swap. You're going to want to switch the display property from none to block and back. I've given you an example below.

    Code:
    <html>
    <head>
    
    <script>
    function expand_collapse(divID)
    {
        for(var i=1; i<=2; i++)
        {
            document.getElementById(i).style.display = 'none';
        }
        document.getElementById(divID).style.display = 'block';
    }
    </script>
    </head>
    <body>
    <a href="javascript:void(0);" onclick="expand_collapse(1)">1</a>&nbsp;<a href="javascript:void(0);" onclick="expand_collapse(2)">2</a><br /><br />
    <div id="1">
        html code 1
    </div>
    <div id="2" style="display: none">
        html code 2
    </div>
    </body>
    What this basically does is everytime you click on either link - it loops through and makes the display property for all of the div's "none" - then it changes the one you selected back to "display:block" so it shows that one. You can use this with as many divs as you'd like, as long as you order them by number and make sure to change the "2" in the for loop to as many divs as you have. Since all the rest of the div's displays are set to none - you don't have to worry about positioning them because they don't have an effect on the layout. Enjoy

  4. #3
    Junior Member
    Join Date
    Jul 2007
    Posts
    2
    Member #
    15558
    I got it working, thanks alot.

    Cheers!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:57 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com