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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:23:24+00:00 2026-05-25T17:23:24+00:00

m having a problem with nested SetInterval’s. My goal is to repeat an animation

  • 0

m having a problem with nested SetInterval’s.
My goal is to repeat an animation of blocks showing in equal intervals.
So my first iteration goes well and each block appears in equal intervals and then all disappear as planned.
But problems start from the second iteration.
They begin to show randomly and in totally different intervals.
Here’s my code you can copy it and see the behavior by yourself:

<style type="text/css">
      #wrap{width:700px; min-height:700px; margin:0 auto;  }
      #wrap div+div,#wrap div+div+div,#wrap div+div+div+div{width:70px; height:70px;  position:absolute; display:none;}
      #wrap div+div{top:340px; left:370px; background-color:#2e9555 }
      #wrap div+div+div{top:340px; left:470px;background-color:#dfe766; }
      #wrap div+div+div+div{top:340px; left:570px; background-color:#1a3c65;}
</style>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>

<script type="text/javascript" >
  $(function(){
      popups(); 
  });

  var y;  
  setInterval(popups,1200);
  function popups(){    
      var x=1;
      y =window.setInterval(function(){ popUpBuble(x); ++x;}, 1200);
  };

  function popUpBuble(index){
      if(index<4){
         $('#wrap div:eq('+index+')').fadeIn('slow');       
      }
      else{
         window.clearInterval(y);
         $('#wrap div:lt(4)').delay(3000).fadeOut(1000);
      }
  }

<body>
        <div id="wrap">
             <div></div>
             <div></div>
             <div></div>
             <div></div>
             <div></div>
        </div>
  </body>

Any ideas how to fix the bug and also how do you minimize the resources taken by setInterval.
It rises memory use every second.

  • 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-25T17:23:25+00:00Added an answer on May 25, 2026 at 5:23 pm

    The main issue here is that your time interval for the first setInterval is too small. This call to popups re-starts the overall animation. If you are trying to start the animation while it is already in motion, this is a problem.

    Increasing the interval to be longer than the overall animation fixes this:

    http://jsfiddle.net/9ZwwN/

    I would however suggest a slightly different approach, though. The nested interval thing as you can see gets very confusing. You may want to consider using callbacks on your animations instead along with delay to remove the intervals all together.

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

Sidebar

Related Questions

We're having a problem combining 'nested files' and excluding files from source control. We're
I'm having a problem with nested model forms that contain radio buttons, when I
I'm having a problem using nested partials with dynamic form builder code (from the
I am new to programming and having some problem figuring out nested loops. I
I'm having this annoying problem with Rails 3 (ruby 1.9.2) and nested resources. In
I am having problem loading data into Nested datagrid. When the user clicks on
I have 2 divs nested within a parent div. Im having a problem setting
How to handle nested lists in Python? I am having problem figuring out the
I am having a problem getting the params of a nested form in the
I'm having two models, the first one ( model_1 ) accepts nested attributes for

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.