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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:22:05+00:00 2026-06-14T11:22:05+00:00

Seems like every 50-100 jsfiddle updates lead me to the stackoverflow community to help

  • 0

Seems like every 50-100 jsfiddle updates lead me to the stackoverflow community to help solve a new issue I create! so Thanks!

Background: I have several functions containing animations, functions are to be fired after the previous one is completed. With some help and research I started using $.when and .promise() to control this stuff over my initial very ugly callback strings & setTimeouts on each function.

My dilemma is this: At some point the user may want to pause everything and resume it again at their leisure. I can’t seem to add this functionality!

I’m able to pause all animations with $(‘div:animated’).stop() but that is temporary as .promise() still resolves! Any way to override that behavior? Any restructuring that may help make a pause and resume easier to implement?

Tomorrow I plan on going down the path of adding all animations to a proxy objects queue but not sure how well creating a global queue on a new object will work with the existing structure. I also intent on looking at adding some boolean to check if value is off then don’t call functions or animate otherwise do. I’m not sure if either of those solutions are the appropriate direction I should take?

after previewing this post I’d also be inclined to learn how I could refactor my nested start button function!

Any direction on implementing pause and resume functionality will be greatly appreciated.

The code below is much simplified and each function contains more elements & animations.

a fiddle here

JS:

    $('#start').click( function() {
    // run a and wait one second, when done run b and wait 1 second...
    a().delay(100).promise().done( function(){
        b().delay(100).promise().done( function(){
            c().delay(100).promise().done( function(){
                d().delay(100).promise().done( function(){
                    e().delay(100).promise().done( function(){
                        f().delay(100).promise().done( function(){
                            alert('all done!');
                        });
                    });
                });
            });
        });
    });


    });

    $('#reset').click( function() {
        $('.box').css({
            top: '0px'
        });
    });
    $('#pause').click( function() {
        $('div:animated').stop();
    });
   function a() {
        return $('.box1').animate({top: '100px'}, 1000, function(){
            $('.box1').animate({top: '50px'}, 1000);        
        });
        return $('.box6').animate({top: '200px'}, 4000);
    }
    function b(){
        return $('.box2').animate({top: '100px'}, 1000);
    }
    function c(){
        return $('.box3').animate({top: '100px'}, 1000, function(){
            $('.box3').animate({top: '50px'}, 1000);        
        });
    }
    function d(){
        return $('.box4').animate({top: '100px'}, 1000);
    }
    function e(){
        return $('.box5').animate({top: '100px'}, 1000, function(){
            $('.box5').animate({top: '50px'}, 1000);        
        });
    }
    function f(){
        return $('.box6').animate({top: '100px'}, 1000);
    }

​
html & CSS

<button id='start'>animate</button>
<button id='reset'>Reset</button>
<button id='pause'>pause</button>
<div class='boxes'>
    <div class='box box1'></div>
    <div class='box box2'></div>
    <div class='box box3'></div>
    <div class='box box4'></div>
    <div class='box box5'></div>
    <div class='box box6'></div>
</div>​
.boxes{position: relative}
.box{width: 40px; height: 40px; background-color: green; position:absolute;}
.box1{left: 0px;}
.box2{left: 60px;}
.box3{left: 120px;}
.box4{left: 180px;}
.box5{left: 240px;}
.box6{left: 300px;}
​

EDIT
You’re answers have provided the learning experience I was looking for; I really appreciate the mind share! My contrived example may not showcase the real world problem enough as the answers posed do not allow multiple animations to fire at the same time? I don’t think at least? For example box1 and box2 may move at the same time, or when box3 fires so does box6. The initial VERY UGLY promise system I implemented used many functions as each function was composed of many animations. How would this be achieved with the proposed answers?

EDIT2
Two answers, charlietfl’s lets me easily add secondary functions that fire simultaneously; very important. Alnitak’s has an elegant way of constructing an array and applying it to the animations that is very easy to change animation types (fadeOut(), fadeIn()).

So what I’m attempting to do is combine the two such that I can create a nested array for secondary animations that uses Alnitaks array format:

['.box1', 'animate', { top:  '50px'}, 1000],

SO in short i’m still working on all answers but getting close / nearly there with charlietfls’s. Adding Alnitak’s array to his or adding charlietfl’s nesting to Alnitak’s.

This got more intense then I ever intended; I appreciate your contributions and code to learn from…. Very informative!

  • 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-14T11:22:06+00:00Added an answer on June 14, 2026 at 11:22 am

    The jQuery method of allowing multiple simultaneous animations is all very well, but when your animations are all sequential it’s overkill.

    I would suggest creating an array of animation descriptions, and then in a simple loop just invoke those one at a time.

    Each description would need to know which element to animate, which function to call, and what the function arguments are.

    Pausing the animation is then simply a question of not progressing through the loop:

    function next() {
        if (!animating) return;
    
        var a = list.shift();
        if (a) {
            var el = a[0];
            var fn = a[1];
            var args = a.slice(2);
            $.fn[fn].apply($(el), args).promise().done(next);
        } else {
            alert('all done!');
        }
    };
    

    See http://jsfiddle.net/alnitak/ANRa3 for a demo.

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

Sidebar

Related Questions

It seems like every time I float two elements to the right, they get
Seriously, it seems like every time I want to make my UI elements talk
This seems like it should be something very easy to do, but every time
Seems like i need some help with a project. I have a routine ,
I want a timer tick/elapsed event inside a new thread. It seems like I
Seems like there should be... Right now it just seems like magic that you
Seems like cuke doesn't show the full error message (at least when problem occurs
Seems like a standard approach for an ioc when given a scenario like (C#
Seems like this should be obvious, but how do I send arrow key presses
Seems like this should be simple, but powershell is winning another battle with me.

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.