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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:44:48+00:00 2026-05-31T19:44:48+00:00

Is there a way I can tell the browser to wait to start on

  • 0

Is there a way I can tell the browser to wait to start on function until after another is completed?

For example, in the following for loop, I’d like for contact() to fire and conclude, prior to moveForward() commencing.

for ($i = 0; $i <= ($slugPace - 1); $i++ ) {
    contract();
    moveForward();
    reset();
};

I attempted using $.when(// your first function).then(// your second function); mentioned in this stackoverflow thread, but the JS functions in the three listed functions continued to fire simultaneously.

Here is the code in total, if that helps:

    //Contracting the slug once:
    function contract(){
        $("#slug").animate({
            marginTop: 0,
            width: $slugThinner,
            height: $slugHigher,
        }, 250);
        $(".slugContainer").animate({
            marginLeft: $slugLeftMargin,
        }, 250);
    };

    //Extending the slug out and move him forward once:
    function moveForward(){
        $slugLeftMargin += $slugStepsLength;
        $("#slug").animate({
            marginTop: $slugMarginJS,
            width: $slugWide,
            height: $slugHigh,
        }, 250);
        $(".slugContainer").animate({
            marginLeft: $slugLeftMargin,
        }, 250);
    };

    function movement(){
        for ($i = 0; $i <= $slugStepsTotal; $i++ ) {
            contract();
            moveForward();
        };
    }

    function reset(){
        if ($slugLeftMargin > $screenWidth) {
            $slugLeftMargin = $slugWide * -1;
            $("#slug").stop().hide;
            $(".slugContainer").stop.css('margin-left',$slugLeftMargin);
            for ($i = 0; $i <= ($slugPace - 1); $i++ ) {
                contract();
                moveForward();
            };
        }
    }

    //Looping the contractions to move our little friend across the screen:
    $("#slug").click(function(){
        //alert('Slug width: ' + $slugWide + ', Slug height: ' + $slugHigh + ', Screen width: ' + $screenWidth + ', Slug steps total: ' + $slugStepsTotal + ', Slug higher: ' + $slugHigher + ', Slug thinner: ' + $slugThinner);
        //alert($slugStepsTotal);
        //alert('One step: ' + $slugStepsLength + '; Total steps: ' + $slugStepsTotal + '; Screen width: ' + $screenWidth);
        $("#slug").show();
        $(".clickMe").fadeOut(300);
        $.when(movement).then(reset());
    });

Thank you in advance for your help.

  • 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-31T19:44:50+00:00Added an answer on May 31, 2026 at 7:44 pm

    In general terms, since you’re using the animate method, you could do something with callbacks, say:

    function contract(callback) {
        $("#slug").animate({
                marginTop: 0,
                width: $slugThinner,
                height: $slugHigher,
            }, 250);
         $(".slugContainer").animate({
                marginLeft: $slugLeftMargin,
         }, 250, function() {
           callback();
          }
        );
    

    And you’d call contract like this:

    contract(function(){ moveForward(); });
    

    You can read-up a bit more about animate here

    That is the basic idea of what you need: callbacks.

    Good luck mate!

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

Sidebar

Related Questions

Is there a way I can tell whether stderr is outputting to a file
Is there a way I can tell (other than in the SVN Log...because it
Is there a way I can tell how many times a form submit button
Is there some way in Flex where I can tell when all of the
Can someone tell me if there is a way for me to use the
Can anyone tell me if there is a way to select a video from
Can you tell me if there's a way to dis- and enable junit.framework.Assert commands
Is there a way to tell the browser to look down a list of
Is there a way to tell browser to show a loader image while a
Is there any way can declare a bean in just like JSP UseBean in

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.