0

I want the numbers inside the list to animate so it displays different number for that duration when button is on click state. But it seems jquery animation is not working inside of it for loop.

$("button").on("click",function(){

 for(var i=0; i < 2; i++ ){

  $({value: $(".number").eq(i).text()}).animate({value: data1[i]},{
       duration: 500,
       easing: 'swing',
       step: function(){
         $(".number").eq(i).text(parseInt(this.value));
       }
     });
  }

});

This is my code example.

1 Answer 1

0

As soon as the loop completes i is 3, ergo all usages of i in the animation callback will be the wrong value.

Sign up to request clarification or add additional context in comments.

3 Comments

So, How should I change for loop with using i?
Thanks so much, Draco18s. After few trial and errors, finally solved problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.