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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:27:27+00:00 2026-06-08T05:27:27+00:00

My brain its going to explode.. why this dont work? im trying to animate

  • 0

My brain its going to explode.. why this dont work? im trying to animate a few divs with time interval and trying to write less code but this dont work

    var cargaCont = function(){
        o = 1;
        var animacion = function(i){
            $('#page2txt'+i).animate({
                height:'20'
            },200,function(){
                $('#page2img'+i).animate({
                    left:'0',
                    right:'0'
                },200,function(){
                    i++;
                    return i;
                });
            });
        }
        while(o < 3){
            setTimeout(function(){o = animacion(o);},200);
        }   
    }
  • 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-08T05:27:29+00:00Added an answer on June 8, 2026 at 5:27 am

    The problem with this code:

    while(o < 3){
        setTimeout(function(){o = animacion(o);},200);
    } 
    

    is by the time the functions delayed by setTimeout are executed, o is already 3 and therefore all calls to animacion pass 3 instead of 1 and 2.

    To circumvent this problem, you should “localize” the value of o by using an immediate function.

    while(o < 3){
        //o out here is from cargaCont
        (function(o){
            //override o by naming the passed variable o
            setTimeout(function(){
                o = animacion(o); //now o refers to the local o
            },200);
        }(o)); //execute inner function, passing in o
    } 
    

    This makes the o used by the functions in setTimeoutto be bound to the o of the local function and not the o of the cargaCont function.

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

Sidebar

Related Questions

Its friday, and in local time the clock is 3.22pm, so my brain wont
My Brain Is Going to Explode.. . I have five images all named 0,1,2,3,4.
I am going brain dead on this; I have several List' defined, based on
My brain had a segfault this morning trying to understand exactly how and when
I think I'm missing something very obvious and its making my brain hurt. class
This may be silly, but it's been nagging the back of my brain for
My brain isn't working. Please, let yours work for mine for 1 minute. The
My brain is fried, so I thought I would pass this one to the
I'm trying to write a small agent to control tomcat, and right now it
A friend and I are going back and forth with brain-teasers and I have

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.