Results 1 to 2 of 2

Thread: Overuse of Show / Hide DIVs?

  1. #1
    Join Date
    May 2006
    Posts
    22

    Overuse of Show / Hide DIVs?

    I'm building a site which is using show / hide divs (I'd prefer to use CSS for the menu, but the client wants specific, non-standard fonts).

    This kinda works for the menu, although I'm thinking of finding a script that saves the menu structure with cookies to save the whole auto-collapse thing. I'm a Scripting novice (I'm at the copy and paste level), so advise appreciated on that.

    I've tweked the menu so that if JavaScript is disabled, the menu is automatically open by setting the DIVs to display:block in the CSS and having an onLoad script to set this to display:none.

    I also want to put a notice that the site works better with JavaScript enabled and give info on how to enable it. This is currently done with an display:block DIV that's hidden by an onLoad JavaScript function.

    The problem is that every time you go to a new page, for a second, everything appears as display:block - so you can see the menu fully opened and the 'how to enable JavaScript' DIV is shown.

    How do I stop this?

    Thanks all.

  2. #2
    Join Date
    May 2006
    Posts
    22
    Sorry:

    CSS Link
    CSS

    JavaScript
    <!-- This is the show / hide script for display:block divs-->
    <script language="JavaScript" type="text/JavaScript">
    function toggleLayer(whichLayer)
    {
    if (document.getElementById)
    {
    // this is the way the standards work
    var style2 = document.getElementById(whichLayer).style;
    style2.display = style2.display? "":"none";
    }
    else if (document.all)
    {
    // this is the way old msie versions work
    var style2 = document.all[whichLayer].style;
    style2.display = style2.display? "":"none";
    }
    else if (document.layers)
    {
    // this is the way nn4 works
    var style2 = document.layers[whichLayer].style;
    style2.display = style2.display? "":"none";
    }
    }
    </script>

    <!-- This is the show / hide script for display:none divs-->
    <script language="JavaScript" type="text/JavaScript">
    function showLayer(whichLayer)
    {
    if (document.getElementById)
    {
    // this is the way the standards work
    var style2 = document.getElementById(whichLayer).style;
    style2.display = style2.display? "":"block";
    }
    else if (document.all)
    {
    // this is the way old msie versions work
    var style2 = document.all[whichLayer].style;
    style2.display = style2.display? "":"block";
    }
    else if (document.layers)
    {
    // this is the way nn4 works
    var style2 = document.layers[whichLayer].style;
    style2.display = style2.display? "":"block";
    }
    }
    </script>
    Body onLoad
    <body onLoad="MM_preloadImages('images/nav/about_mauleverer_2.gif','images/nav/news_2.gif','images/nav/buying_collecting_2.gif','images/nav/mauleverer_collection_2.gif','images/nav/oak_2.gif','images/nav/pewter_2.gif','images/nav/viewing_2.gif','images/nav/contact_2.gif','images/nav/how_we_work_2.gif'); javascript:toggleLayer('buying_collecting'); javascript:toggleLayer('mauleverer_collection'); javascript:toggleLayer('how_we_work'); javascript:toggleLayer('javacheck');">

Similar Threads

  1. Help with cut and paste javascript slide show on my site?
    By Ella in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 29 Aug 2006, 10:06 PM

Posting Permissions

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