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

  • Home
  • SEARCH
  • 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 8806947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:15:12+00:00 2026-06-14T02:15:12+00:00

I am working on a nested menu, and when my mouse move over a

  • 0

I am working on a nested menu, and when my mouse move over a option, a sublist will show up.
Here is my hover function:

$( ".sublist" ).parent().hover( function () {
    $(this).toggleClass("li_hover",300); //use to change the background color
    $(this).find(".sublist").toggle("slide", {}, 500); //sub list show / hide
});

Now, I want add a short period before the sublist shows up to prevent the crazy mouse moving from user. Does somebody have a good suggestion on this?


Update:

Thanks for you guys, I did a little bit change on my program, recently it looks like this:

function doSomething_hover (ele) {
    ele.toggleClass("li_hover",300);
    ele.find(".sublist").toggle("slide", {}, 500);
}

$(function () {
    $( ".sublist" ).parent().hover( function () {
        setTimeout(doSomething_hover($(this)), 3000);
    });
}):

This is weird that setTimeout will not delay anything. but if I change the function call to doSomething_hover (without “()”), the function will delay good. but i can not pass any jquery element to the function, so it still not works, could somebody tell me that how to make doSomething_hover($(this)) work in setTimeout ?


Update 2:
Got the setTimeout work, but it seems not what I want:
What I exactly want is nothing will happen, if the mouse hover on a option less than 0.5sec.

Anyway, here is the code I make setTimeout work:

function doSomething_hover (ele) {
    ele.toggleClass("li_hover",300);
    ele.find(".sublist").toggle("slide", {}, 500);
}

$(function () {
    $( ".sublist" ).parent().hover( function () {
        var e = $(this);
        setTimeout(function () { doSomething_hover(e); }, 1000);
    });
}):

Final Update:
I got this work by using clearTimeout when I move the mouse out.
so the code should be:

    $( ".sublist" ).parent().mouseover( function () {
        var e = $(this);
        this.timer = setTimeout(function () { doSomething_hover(e); }, 500);
    });

    $( ".sublist" ).parent().mouseout ( function () {
        if(this.timer){
            clearTimeout(this.timer);
        }
        if($(this).hasClass("li_hover")){
            $(this).toggleClass("li_hover");
        }
        $(this).find(".sublist").hide("slide", {}, 500);

    });

This is the part in the $(document).ready(). Other code will be same as above.


真. Final Update:
So, mouseover and mouseout will lead to a bug sometime, since when I move the mouse to the sublist, the parents’ mouseover event will be fire, and hide the sublist.
Problem could be solved by using hover function:

    $( ".sublist" ).parent().hover( 
        function () {
            var e = $(this);
            this.timer = setTimeout(function () { doSomething_hover(e); }, 500);
        },
        function () {
            if(this.timer){
                clearTimeout(this.timer);
            }
            $(this).find(".sublist").hide("slide", {}, 500);
            if($(this).hasClass("li_hover")){
                $(this).toggleClass("li_hover",300);
            }
        }
    );

Thanks all

  • 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-06-14T02:15:13+00:00Added an answer on June 14, 2026 at 2:15 am

    Try this please:

    Code

    setInterval(doSomthing_hover, 1000);
    
    
    function doSomthing_hover() {
        $(".sublist").parent().hover(function() {
    
            $(this).toggleClass("li_hover", 300); //use to change the background color
            $(this).find(".sublist").toggle("slide", {}, 500); //sub list show / hide
        });
    
    }​
    

    SetTime vs setInterval

    At a fundamental level it’s important to understand how JavaScript timers work. Often times they behave unintuitively because of the single thread which they are in. Let’s start by examining the three functions to which we have access that can construct and manipulate timers.

    var id = setTimeout(fn, delay); – Initiates a single timer which will call the specified function after the delay. The function returns a unique ID with which the timer can be canceled at a later time.

    var id = setInterval(fn, delay); – Similar to setTimeout but continually calls the function (with a delay every time) until it is canceled.

    clearInterval(id);, clearTimeout(id); – Accepts a timer ID (returned by either of the aforementioned functions) and stops the timer callback from occurring.

    In order to understand how the timers work internally there’s one important concept that needs to be explored: timer delay is not guaranteed. Since all JavaScript in a browser executes on a single thread asynchronous events (such as mouse clicks and timers) are only run when there’s been an opening in the execution.

    Further read this: http://ejohn.org/blog/how-javascript-timers-work/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a navigation control. I have nested lists which creates this: What
Сould you please give me working example of nested editors ? I've read this
I have this UL/LI . Users will choose them from a menu and what
Is there a way to use Array_unique function working for nested array like below?
I have a menu using pure CSS, hover a parent li item display the
Here is my question. I am having this simple menu. <div id=menu> <ul> <li>
I'm working with a tree structure in MySQL that is respresented using the nested
Good day. Has somebody working solution for deleting asset in nested form in Carrierwave?
Working with an undisclosed API, I found a function that can set the number
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports

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.