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 7564705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:57:56+00:00 2026-05-30T13:57:56+00:00

Im trying to add a delay that works on my dropdown menu if the

  • 0

Im trying to add a delay that works on my dropdown menu if the person misstakly
moves mouse outside the menu. I have tried many solutions found on here but non of them
seam to work.

Edit:
here is the link to jsfiddle for a complite example

Edit: 5

$(function () {
            var slideDownTime = 400;
            var firstRun = true;

            var $menu = $('#menu'),
            $submenus = $menu.find('ul'),
            $items = $menu.find('li'),
            hide = function ($el, $instantHide) {
                if (!firstRun) {
                    if (!$instantHide) {
                        // force the menu item to show.
                        $el.css({ visibility: "visible", display: "block" });

                        var hideMenuId = setTimeout(function () {
                            $el.hide().css('visibility', 'hidden');
                        }, 5000);

                        $el.data('hideMenuId', hideMenuId);
                    } else {
                        $el.hide().css('visibility', 'hidden');
                    }
                } else {
                    $el.hide().css('visibility', 'hidden');
                }
            },
            show = function ($el) {
                clearTimeout($el.data('hideMenuId'));
                $el.css('visibility', 'visible').stop(1, 1).slideDown(slideDownTime);

                hide($el.parent().siblings().find("ul"), true); // <-- this line hides the other submenus if hovered.

                var singleLevel = $el.parent().find("ul > li:not(:has(ul)) > a");
                singleLevel.hover(function () {
                    hide($(this).closest("ul").children('li').not(this).find("ul"), true);
                }, function () {
                });

                firstRun = false;
            };

            $menu.focusout(hide($submenus));
            $items.hover(function () {
                show($(this).children('ul'));
            }, function () {
                hide($(this).children('ul'), false);
            });

             // find the root elemement level with no children.
             $menu.find("> li a").not("ul li ul a").not("li:has(ul) > a").hover(function () {
                  //hide the unwantend menu items.
                  hide($(this).closest("ul").children('li').not(this).find("ul"), true);
            }, function () {
            });

 });

Ok this is what i ended up with.
but can this not be made with less code ?

Edit: 6
The jsfiddle link is now updated to the latest verision.

  • 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-30T13:57:57+00:00Added an answer on May 30, 2026 at 1:57 pm

    Try using focusout() with a delay(). Also, I don’t think you need all that if else logic. Every submenu is an <ul> children of $('#menu') and at the same time, children of a <li>, so you can easily create a function to show or hide a menu which accepts a jQuery object as parameter. Without your html code I can’t say for sure, but something like this should work. Adapt to your needs.

    var $menu = $('#menu'), // Assuming this is a `<ul>`
        $submenus = $menu.find('ul'),
        $items = $menu.find('li'),
        hide = function($el){ 
            $el.delay(500).hide().css('visibility', 'hidden'); 
        },
        show = function($el){ 
            $el.css('visibility', 'visible').stop(1, 1).slideDown(); 
        };
    
    $menu.focusout(hide($submenus));
    $items.hover(function(){
        show($(this).children('ul'));
    }, function(){
        hide($(this).children('ul'));
    });
    

    Also this:

    element.css('visibility') != "visible" && element.css('display') != "block"
    

    is the same as:

    element.is(':visible')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add several labels that appear sequentially with a time delay
I'm trying to add delay to a simple drop down menu. With the following
I am trying to add a timed delay in a C++ program, and was
I'm trying add a tab to my web page that looks like this: Using
trying to add an ExpiresDefault ExpiresByType to content on my website so that way
I'm trying to fade out my contact form then add a delay of 2000
I am trying to create a sleep/delay procedure in 16bit MASM Assembly x86 that
I'm trying to add SlideLock to my app for a version that I am
I'm trying to add a small delay in the .hover() callback before running further
I'm trying add some implicit rules in CMake that will generate direct dependencies (like

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.