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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:12:31+00:00 2026-06-08T22:12:31+00:00

I am using jQuery Transit to animate a changing element. I am animating multiple

  • 0

I am using jQuery Transit to animate a changing element.

I am animating multiple boxes using a for loop.

The javaScript:

<script>
window.onload = function(){
  $('div.test').mouseover(function(){
    for (var i = 0; i < 2; i++){
      console.log(i+' Starting Loop');

      //Rotate box animation
      $('div.test' && '.'+i).transition({
        perspective: '100px',
        rotateY: '-180deg',
        x: '-90px'
      }, 'slow',function(){
        //On completion code.
        $('div.test' && '.'+i).append(' With Changed Text');
        console.log(i + 'Text has been changed');

        //Rotate back
        $('div.test' && '.'+i).transition({
          perspective: '100px',
          rotateY: '0deg',
          x: '0px'
        }, 'slow');
      });
      console.log(i + 'finished the loop');
      alert(i + ' finished loop');
    }
  });
}
</script>

And the HTML:

<body>
<div class='test 0'>
  Box1
</div>
<div class='test 1'>
  Box2
</div>
</body>

It is supposed to work by making the box move, make the appropriate changes, and then move back to its original position.

However, instead of waiting for the first animation to finish before moving on to the next iteration of the for loop, it seems to be waiting until the for loop is finished before it executes the $.transition() functions.

So when the $.transition() functions are called, i = 2. Therefore the $.append() function is appending to an element with the class ‘.2’, which does not exist.

Is there any way to make sure the animations execute within the loop properly?

NOTE This is a simplified version of my real code. I would normally be appending different values for each box. I am also iterating through a list which could possibly be longer than 2.

EDIT I found a solution by recursively iterating through the array. Here it is.

  • 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-08T22:12:33+00:00Added an answer on June 8, 2026 at 10:12 pm

    Just so this has an official answer, here is my new javaScript code.

    <script>   
    function rotateBox(list){
      if (list.length <= 0){
        return;
      }
    
      var i = list.pop();
      console.log("i: "+i);
    
      $('div.test' && '.'+i).transition({
        perspective: '100px',
        rotateY: '-180deg',
        x: '-90px'
      }, 'slow',function(){
        //On completion code.
        $('div.test' && '.'+i).append(' With Changed Text');
        console.log(i + 'Text has been changed');
    
        //Rotate back
        $('div.test' && '.'+i).transition({
          perspective: '100px',
          rotateY: '0deg',
          x: '0px'
        }, 'slow', function(){
    
          //Recursion!
          rotateBox(list);
        });
      });
    
    }
    
    window.onload = function(){
    
      //a list of arbitrary values that match with a <div> class
      list = [0, 1];
    
      $('div.test').mouseover(function(){
        rotateBox(list);
    
        //Just in case you feel like running through it again
        list = [0, 1];
      });
    };
    </script>
    

    And a demo: http://jsfiddle.net/bHsL3/6/.

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

Sidebar

Related Questions

Using jquery, How can I create multiple draggables using loops through javascript? I want
Using jQuery validation - validating on blur: $('input, select, radio, checkbox').blur(function(){ $(#createAccount).validate().element(this); }); If
Using jQuery 1.7.2 $(function(){ $('#parentElem').mouseenter(function(){ $('.myElem').animate({opacity:1}, 'fast'); }).mouseleave(function(){ $('.myElem').stop().animate{opacity:0}, 'slow'); }); }); In this
I can't repeat animation with the following example (using jQuery Transit ) $(#rotateDiv2).button().click(function() {
Using jQuery autocomplete.. Want to replace hello in script below with javascript to identify
Using jQuery Nearest Element , I would like to select elements in a circular
Using jQuery, how can I get the input element that has the caret's (cursor's)
Using jQuery, one can easily find out whether a particular element is visible using
Using jQuery, I make these changes in the DOM: $(document).ready(function() { $('.editable').click(function() { var
Using jQuery, I'm trying to change the selected option in a SELECT element to

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.