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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:15:36+00:00 2026-06-02T12:15:36+00:00

I’m having a little problem with the setTimeout-function. $(this) is every DOM-Element with a

  • 0

I’m having a little problem with the setTimeout-function.

$(this) is every DOM-Element with a specific class.

When the mouse enters an elememt, and then leave it, there is no problem. But when the mouse leaves an element directly to another (within the 500ms timeout) the first element (that one, the mouse left from) never fades out.

So the new mouseenter-Event kind of prevent the timeOut to call the function.
Without the setTimeout-wrapper everything is just working fine.

Here’s my code:

$(this).hover(methods['mouseenterManager'], methods['mouseleaveManager']);


/**
 * manage mouseenter events
 */
mouseenterManager: function() {

    clearTimeout(timer);

    //create toolbar, if no toolbar is in dom
    if ($(this).data("layouter").toolbar == undefined) {

        //get bottom center of this element
        pos_left = ($(this).width() / 2) + $(this).offset().left;
        pos_top = $(this).height() + $(this).offset().top;

        //create toolbar element
        toolbar = $('<div style="display:none; left:' + parseInt(pos_left) + 'px; top:' + parseInt(pos_top) + 'px;" class="layouter_bar"><ul><li><a class="edit" href="javascript:;">Edit</a></li><li><a class="copy" href="javascript:;">Edit</a></li><li><a class="remove" href="javascript:;">Edit</a></li></ul></div>');

        //bind this element to toolbar
        toolbar.data("layouter", {
            parent: $(this),
        });

        //bind toolbar to this element
        data = $(this).data("layouter");
        data.toolbar = toolbar;
        $(this).data("layouter", data);

        //bind this element to toolbar
        data = toolbar.data("layouter");
        data.parent = $(this);
        toolbar.data("layouter", data);

        element = $(this);
        toolbar.mouseleave(function() {

            toolbar = $(this);
            timer = setTimeout(function() {
                if (!toolbar.is(":hover") && !element.is(":hover")) {

                    toolbar.fadeOut("fast", function() {
                        $(this).remove();
                    });

                    data = element.data("layouter");
                    data.toolbar = undefined;
                    element.data("layouter", data);
                }
            }, 500);
        });

        //display the toolbar  
        $("body").append(toolbar);
        toolbar.fadeIn("fast");
    }
},


/**
 * manage mouseleave events
 */
mouseleaveManager: function() {

    toolbar = $(this).data("layouter").toolbar;
    element = $(this);
    if (toolbar != undefined) {
        timer = setTimeout(function() {
            if (!toolbar.is(":hover")) {

                toolbar.fadeOut("fast", function() {
                    $(this).remove();
                });

                data = element.data("layouter");
                data.toolbar = undefined;
                element.data("layouter", data);
            }
        }, 500);
    }
},

};​

Any ideas?

thank you!

  • 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-02T12:15:38+00:00Added an answer on June 2, 2026 at 12:15 pm

    It looks to me like you’re using a lot of global variables and when you go into another element, the value of all those global variables gets changed. Your timeout function is referencing those global variables so it doesn’t work properly when they’ve been changed by entering another element.

    It also looks to me like as soon as you enter another element, you clear the timer to prevent it from running and since it’s a global timer, there is only one so you have killed the timer that you want to fire.

    For the global variable problem, put var in front of all variables that should be local like this:

    var toolbar = $(this).data("layouter").toolbar;
    var element = $(this);
    

    and

    //get bottom center of this element
    var pos_left = ($(this).width() / 2) + $(this).offset().left;
    var pos_top = $(this).height() + $(this).offset().top;
    

    For the timer issue, it appears to me like you need to NOT have a single global timer, but need a timer for each element. That is a bit more complicated. Without something I can run and test, I can’t be sure if this works without any other changes, but this is steps in the right direction to fix the variables to be local and to make the timer be local for each element:

    $(this).hover(methods['mouseenterManager'], methods['mouseleaveManager']);
    
    
    /**
     * manage mouseenter events
     */
    mouseenterManager: function() {
    
        var self = $(this);
        var timer = self.data("timer");
        if (timer) {
            clearTimeout(timer);
        }
    
        //create toolbar, if no toolbar is in dom
        if (self.data("layouter").toolbar == undefined) {
    
            //get bottom center of this element
            var pos_left = ($(this).width() / 2) + $(this).offset().left;
            var pos_top = $(this).height() + $(this).offset().top;
    
            //create toolbar element
            var toolbar = $('<div style="display:none; left:' + parseInt(pos_left) + 'px; top:' + parseInt(pos_top) + 'px;" class="layouter_bar"><ul><li><a class="edit" href="javascript:;">Edit</a></li><li><a class="copy" href="javascript:;">Edit</a></li><li><a class="remove" href="javascript:;">Edit</a></li></ul></div>');
    
            //bind this element to toolbar
            toolbar.data("layouter", {
                parent: self,
            });
    
            //bind toolbar to this element
            var data = self.data("layouter");
            data.toolbar = toolbar;
            self.data("layouter", data);
    
            //bind this element to toolbar
            data = toolbar.data("layouter");
            data.parent = self;
            toolbar.data("layouter", data);
    
            var element = self;
            toolbar.mouseleave(function() {
    
                toolbar = self;
                timer = setTimeout(function() {
                    self.data("timer", null);
                    if (!toolbar.is(":hover") && !element.is(":hover")) {
    
                        toolbar.fadeOut("fast", function() {
                            $(this).remove();
                        });
    
                        data = element.data("layouter");
                        data.toolbar = undefined;
                        element.data("layouter", data);
                    }
                }, 500);
                self.data("timer", timer);
            });
    
            //display the toolbar  
            $("body").append(toolbar);
            toolbar.fadeIn("fast");
        }
    },
    
    
    /**
     * manage mouseleave events
     */
    mouseleaveManager: function() {
    
        var toolbar = $(this).data("layouter").toolbar;
        var element = $(this);
        var timer = element.data("timer");
        if (toolbar != undefined && !timer) {
            timer = setTimeout(function() {
                element.data("timer", null);
                if (!toolbar.is(":hover")) {
    
                    toolbar.fadeOut("fast", function() {
                        $(this).remove();
                    });
    
                    var data = element.data("layouter");
                    data.toolbar = undefined;
                    element.data("layouter", data);
                }
            }, 500);
            element.data("timer", timer);
        }
    },
    
    };​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.