jquery “animate” variable value

后端 未结 9 967
说谎
说谎 2021-02-04 05:36

I need to \"animate\" a variable with jquery.

Example: The variable value is 1. The value should be 10 after 5 seconds. It should be increase \"smoothl

9条回答
  •  我寻月下人不归
    2021-02-04 06:04

    What you require is the step parameter in the $().animate function.

    var a = 1;
    jQuery('#dummy').animate({ /* animate dummy value */},{
        duration: 5000, 
        step: function(now,fx){ 
            a = 1 + ((now/100)*9); 
        }
    });
    

    demo

提交回复
热议问题