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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:00:04+00:00 2026-05-20T08:00:04+00:00

I have this function and I am wondering why the setTimeout is not working:

  • 0

I have this function and I am wondering why the setTimeout is not working:

$(document).ready(function() {      
    $('.sliding .text').css("top","130px")     

    $('.sliding').mouseenter(function() {       
        mouseOverTimer = setTimeout(function() {
            $(this).find('.text').animate({"top": "0"}, 200);             
        }, 500);       
    })
    .mouseleave(function() { 
        $(this).find('.text').delay(500).animate({"top": "130px"}, 400); 
    });       
});     

I tried wrapping the mouseenter event in the timeout, but that didn’t seem like a great idea. I just want the animation on mouseenter to only work after the mouse has been over it for at least half a second.

Alternatively, is there a better way of doing it in jQuery?

  • 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-20T08:00:05+00:00Added an answer on May 20, 2026 at 8:00 am

    The this value inside your timeout handler will not be what you think it’ll be. Add an explicit variable:

       $('.sliding').mouseenter(function() {   
            var self = this;    
            mouseOverTimer = setTimeout(function() {
                $(self).find('.text').animate({"top": "0"}, 200);             
            }, 500);       
        })
    

    Also you should declare “mouseOverTimer” as a local variable outside the handler setup code (that is, as a local variable of the “ready” handler) and then cancel the timeout in the “mouseleave” handler:

        var mouseOverTimer = null;
    
       $('.sliding').mouseenter(function() {   
            var self = this;    
            mouseOverTimer = setTimeout(function() {
                $(self).find('.text').animate({"top": "0"}, 200);             
            }, 500);       
        })
       .mouseleave(function() { 
            $(this).find('.text').delay(500).animate({"top": "130px"}, 400); 
            cancelTimeout(mouseOverTimer);
        });       
    

    As I look at this, I’m pretty sure that the “mouseleave” code isn’t really what you want; specifically I think the delay is probably unnecessary. I’m not 100% sure about what you want things to look like, however.

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

Sidebar

Related Questions

$(document).ready(function() { $('.watermark').focus(function() { if (this.className == 'watermark') { this.className = ''; this.value =
I currently have this method: public function getUser($id) { $user = $this->db->getSingleRecord(SELECT user_id, user_login,
I'm doing an animation using javascript: function animate(){ window.setTimeout(function(){ //Do a new frame and
I trying to change a website that is already up and running. I have
I am wrapping a C function which performs a blocking operation (select) and then
Perhaps I'm overlooking something obvious but I was wondering what the fastest way to
I'm using cloneNode(true) to make copies of DOM elements (for instance a div containing
I'm trying to use one of my PHP functions within one of my jQuery
I've got a bunch of stateful functions inside a State monad. At one point

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.