简体   繁体   中英

jquery animation with no duration

I'm trying to access the values of a jQuery animation without setting a duration. (but need the duration property to tell the animation how many steps I want to have). Actually I dont't want to animate anything, I just want jQuery to calculate the values between min and max. The reason why I dont't calculate them myself is that I want to make use of jQuery's easings and those of the jQuery Easing Plugin

var min = 0,
    max = 50,
    steps = 20,
    values_arr = [];

$({value: min}).animate({value: max}, {
    duration: steps, 
    step: function (v) {values_arr.push(v)}
})

Is there any way not to wait for the animation but get all the values instantly?

You can call the ease functions directly like this :

$.easing.easeInQuad(null, elapsedTime, initialValue, changeAmount, duration);

Just change elapsedTime from 0 to duration to get the values you need. Notice that you pass the amount of change, not the destination value.

With your data, you could do something like this:

var min = 0,
    max = 50,
    steps = 20,
    values_arr = [];


for(var i = 0; i < steps; i++){
    values_arr.push($.easing.easeInQuad(null, i, min, max, steps));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM