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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:49:17+00:00 2026-06-15T11:49:17+00:00

I am animating 3 points recursively. I would like to stop recursion after clicking

  • 0

I am animating 3 points recursively. I would like to stop recursion after clicking #myElement.

Here is my code:

    $(document).ready(function(){       
        var positions = {
            'pos1': {"X": $('#point_1').css('left'), "Y": $('#point_1').css('top')},
            'pos2': {"X": $('#point_2').css('left'), "Y": $('#point_2').css('top')},
            'pos3': {"X": $('#point_3').css('left'), "Y": $('#point_3').css('top')},
        };

        animate3Points(positions);
    }); 

    function animate3Points(p) {
        animatePoints('#point_3', p, p.pos1);
        animatePoints('#point_2', p, p.pos2);
        animatePoints('#point_1', p, p.pos3);
    }

    function animatePoints(selector, p, pos) {
        $(selector).animate({
            'left': pos.X , 
            'top':  pos.Y
        }, 2000, 'easeInOutQuad', function() {

            // while #myElement has not been clicked,
            // call again animate3points for recursivity :

            if (selector == '#point_1') { // just to be recalled one time
                p2 = changePosition(p);
                animate3Points(p2);
            }

            // end while

        });
    }

    function changePosition(obj) {
        firstEl = obj.pos1;
        obj.pos1 = obj.pos2;
        obj.pos2 = obj.pos3;
        obj.pos3 = firstEl;

        return obj;
    }   

Animation works but need maybe to be implemented in another way to stop recursion.

An idea ?

  • 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-15T11:49:19+00:00Added an answer on June 15, 2026 at 11:49 am

    You should make use of a global variable instantiated outside your function and use it as the logical conditional for when the recursive calls should stop. For instance:

    var keepAnimating = true;
    
    function animate3Points(p) {
        if(keepAnimating) {
            animatePoints('#point_3', p, p.pos1);
            animatePoints('#point_2', p, p.pos2);
            animatePoints('#point_1', p, p.pos3);
        }
    }
    

    On your click event, you need to set keepAnimating = false;. This will stop the recursion, but you may also need to stop the animation.

    However, infinite recursion is a really bad idea. You will cause the browser to use a lot of memory. You should optimize your code to use loops instead of recursion.

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

Sidebar

Related Questions

I m un-animating a list using this code... function unanimate_li() { $li.filter(':last') .animate({ height:
Can someone help me w/ this code snippet. I'm animating a block of content
I am wondering how I would go about animating a UIView's to a specific
So I have the following code where I am releasing an object after pushing
I have a drawing app and I would like for my users to be
Greetings! I am currently working on a Silverlight project and I would like to
Here's the basic code to get started with: [UIView transitionWithView:self.view duration:2.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^ {
I am animating an image rotation using a doubleanimation linked to a click event
I am animating in divs in a specific order. I start them all at
I'm animating these images being raised from the bottom of the screen and rotated.

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.