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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:24:26+00:00 2026-06-01T00:24:26+00:00

I have this istuation. I have a setTimeout to a function in which I

  • 0

I have this istuation. I have a setTimeout to a function in which I fade out and fade in an element. In a few seconds this timeout is cleared with cleartimeout and right after is called .hide() to hide this element. The problem is that sometimes it doesnt hide the element. I have a feeling it has something to do with timing.

Example:

function first_func(){
    $('.element').fadeOut(function(){
        // Do other stuff like change element's position
        $('.element').fadeIn();
    });

    interval1 = setTimeout(function(){first_func()},500);           
}

function second_func(){
    countdown--;
    if (countdown<0){
        last_func();
    }
    interval2 = setTimeout(function(){second_func()},1000);         
}

function begin_func(){
    first_func();
    second_func();
}

function last_func(){
    clearTimeout(interval1);
    clearTimeout(interval2);
    $('.element').hide();
}

So basically the problem is that in last_func I clear both intervals and HIDE the element, but sometimes the element is still visible on the page. So I am guessing that it does hide but the interval is still in progress and it fades back in.

If anyone would have some suggestion please

  • 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-01T00:24:27+00:00Added an answer on June 1, 2026 at 12:24 am

    Just a suggestion, but this bit appears wrong to me:

    function second_func(){
        countdown--;
        if (countdown<0){
            end_func();
        }
        interval2 = setTimeout(function(){second_func()},1000);         
    }
    

    Even if you’re calling end_func() to stop everything, you’re setting a new timeout after that.

    function second_func(){
        countdown--;
        if (countdown<0){
            end_func();
        } else {
            interval2 = setTimeout(second_func, 1000);
        }       
    }
    

    Another hint: To avoid that running fadeIn/fadeOuts affect the hiding of the element, you should clear the animation queue:

    $('.element').stop(true, true).hide();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into this situation today. I have an object which I'm testing for
i have this situation: <a href=# onClick=submitNotification(1);>click1</a> <a href=# onClick=submitNotification(2);>click2</a> <a href=# onClick=submitNotification(3);>click3</a> function
I have this situation: I have a class which keeps track of an array
I have this situation which is rather frustrating... I have some user controls where
I have this situation where i want to call a certain element depended on
I have a timer setup like so: var timerID; $this.hover(function(){ $this.find('.stage_obj').each(function(index){ var current_obj =
I have this situation: MySQL - Newbie question: Which are the PK and the
i have this situation, i have a winform which has arround 10 to 15
I have this situation: { float foo[10]; for (int i = 0; i <
I have this situation where I want to display a list of Administration objects

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.