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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:35:44+00:00 2026-06-12T07:35:44+00:00

I have the following javascript using jquery code: function MakeAnimation(anim_times) { for (k=1; k<=anim_times;

  • 0

I have the following javascript using jquery code:

function MakeAnimation(anim_times)
{
    for (k=1; k<=anim_times; k++)
    {
        if ( $("#one").position().top >= 250 ) {
            $("#one").animate({ top: '50px' }, 200, function() {});
        } else {
            $("#one").animate({ top: '+=50' }, 200, function() {});
        }
    }
}

and on the html body:

<button onclick="MakeAnimation(1);">step 1</button>
<button onclick="MakeAnimation(20);">step 20</button>
<div id="one" style="background-color:red; width:100px; height:100px; position:absolute; top:50px;"></div>

both buttons calling the same function, but when the function called with 20 times for for loop… the 5th line [ if ( $(“#one”).position().top >= 250 ) { ] does not work

any suggestions ?

thanks

  • 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-12T07:35:45+00:00Added an answer on June 12, 2026 at 7:35 am

    Seems to be working as expected. I’ve created a fiddle for this.

    Sorry, my bad! To answer AkisC’s question, for loops are synchronous, but animations are asynchronous (ref. Wait for a jQueryanimation to complete within for loop).
    Thus, for the 2nd button, we always get ’50’ as the top value on every iteration and the if ( $("#one").position().top >= 250 ) { is never executed.

    I’ve modified my fiddle with the new approach: http://jsfiddle.net/kayen/3SSeu/

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

Sidebar

Related Questions

I have the following Javascript code (using jQuery): floatUpAndDown(); function floatUpAndDown() { $(#bird).animate({top: '+=30px'},
Hello I have the following code: Javascript/jQuery: $(document).ready(function() { $(.clickMe).click(function() { $(.textBox).toggle(); }); });
I have the following JavaScript I am using to save selected check boxes: function
I have the following code in HTML and wanted to replace them using javascript
I have a javascript code using which I want to accomplish the following .
I have the following JavaScript/jQuery code that starts the listener that highlights the DOM
I have the following Javascript code that works perfectly: $(document).ready(function() { $(#Select1).setDefault(); $(#Select2).setDefault(); $(#Select3).setDefault();
I have the following Delete confirmation code using jquery. The issue is that it
I have the following jQuery code which I'm using to populate a jqGrid. It
I have the following jQuery Mobile HTML code, the navbar's content is set using

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.