Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5956339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:14:34+00:00 2026-05-22T18:14:34+00:00

This started from a related question . After getting a brilliant answer I ran

  • 0

This started from a related question. After getting a brilliant answer I ran into an unforeseen gap in functionality: how can I show a menu open by default?

More specifically if a user lands on a page that exists in my sub-nav I want to have that sub-nav open with the current page highlighted. If they use the menu to browse around it will change accordingly, but always go back to the default state if they don’t make a selection.

The code I’m basing this off can be found in this jsfiddle.

The menu structure is like:

<div id="mnav">
    <ul id="buttons">
        <li class="one"><a href="#">Main 1</a></li>
        <li class="two"><a href="#">Main 2</a></li>
        <li class="three"><a href="#">Main 3</a></li>
        <li class="four nav-dark"><a href="#">Main 4</a></li>
    </ul>
</div><!-- /mnav -->
<div id="snav">
    <ul class="snav-one">
        <li><a href="#">Sub 1.1</a></li>
        <li><a href="#">Sub 1.2</a></li>
        <li><a href="#">Sub 1.3</a></li>
    </ul>
    <ul class="snav-two">
        <li><a href="#">Sub 2.1</a></li>
        <li><a href="#">Sub 2.2</a></li>
    </ul>
</div><!-- /snav -->

It was suggested that the basic idea is on hover-out to set things back to the way they were and that makes perfect sense, but how do you save the initial state the menu is in?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:14:35+00:00Added an answer on May 22, 2026 at 6:14 pm

    Based on that jsFiddle code, one approach would be:

    1. The server sets a global variable in the page GBL_bNoDefaultMenu to true or false depending on whether that page has a default sub-menu. (JS could set the variable in ajaxified pages.)

    2. The server also marks the default sub-menu with the class defaultMenu.
      EG: <ul class="snav-two defaultMenu">

    3. Be sure the page has a style like:

      #snav ul.defaultMenu {
          display: block;  /* Or the correct visible display mode.*/
      }
      
    4. Then code like the following should work.
      Notice that all of the main-nav buttons need a hover now. Also, Everything’s been consolidated into one hover() call. And depending on the production page, further simplification may be possible.

    See the demo at jsFiddle.

    $("#buttons li, #snav ul").hover (function (zEvent) {MenuOpenCloseErgoTimer (zEvent); } );
    
    function MenuOpenCloseErgoTimer (zEvent)
    {
        var dDelay;
        var ActionFunction = null;
    
        if (zEvent.type == 'mouseenter')
        {
            if (zEvent.currentTarget.nodeName  == 'LI')        //-- Main nav.
            {
                dDelay          = 300;
                ActionFunction  = function (node) {
                    //--- The first class is a special tie to a submenu, if it exists
                    var subnav = 'ul.snav-' + $(node).attr ('class').split (' ')[0];
                    $("#snav ul").hide ();
                    $("#snav").find (subnav).show ();
    
                    //--- Not sure what's going on with the "open" class.  It's irrelevant to this demo.
                    if (GBL_bNoDefaultMenu)
                        $("#snav").stop (true, true).slideDown ('fast').addClass ("open");
                };
            }
            else //-- zEvent.currentTarget.nodeName  == 'UL'   //-- Sub nav.
            {
                dDelay          = 0;
                ActionFunction  = function (node) {
                    $(node).show ();
    
                    if (GBL_bNoDefaultMenu)
                        $("#snav").stop (true, true).slideDown ('fast').addClass ("open");
                };
            }
        }
        else //-- zEvent.type == 'mouseleave'
        {
            //--- Actions for main nav and sub nav are the same.
            dDelay          = 200;
            ActionFunction  = function (node) {
                if (GBL_bNoDefaultMenu)
                    $("#snav").stop (true, true).slideUp ('fast').removeClass ("open");
                $("#snav ul").hide ();
                $("#snav ul.defaultMenu").show ();
            }
        }
    
        if (typeof this.delayTimer == "number")
        {
            clearTimeout (this.delayTimer);
        }
        this.delayTimer     = setTimeout (function() { ActionFunction (zEvent.currentTarget); }, dDelay);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This started as a question, but turned into a solution as I did some
[Disclosure: This question is slightly related to my previous question .] As you can
My Java application is started from within a native program through java.dll. This native
This post started as a question on ServerFault ( https://serverfault.com/questions/131156/user-receiving-partial-downloads ) but I determined
I originally started this question in another thread, but that thread was sorta, kinda
This question is related to this other question @ SuperUser . I want to
(This question is indirectly related to a programming issue I'm having; if you think
This might not be exactly a programming question but it is related to programmers
First this IS a Java question so forgive this first C#-related explanation... I've most
From a related question asked by Bi, I've learnt how to print a matching

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.