You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
633 B
26 lines
633 B
/**
|
|
* 数字过渡
|
|
*/
|
|
import nextTick from './nextTick';
|
|
|
|
export default (startValue, endValue, callbackFn, duration = 500) => {
|
|
const fromValue = parseFloat(startValue);
|
|
const toValue = parseFloat(endValue);
|
|
if (fromValue == toValue) {
|
|
return callbackFn(toValue);
|
|
}
|
|
const frequency = 20; // 变化频次
|
|
let times = 1;
|
|
async function anime() {
|
|
await nextTick(duration / frequency);
|
|
if (times < frequency) {
|
|
const currValue = fromValue + (toValue - fromValue) * times / frequency;
|
|
callbackFn(currValue);
|
|
times += 1;
|
|
anime();
|
|
} else {
|
|
callbackFn(toValue);
|
|
}
|
|
}
|
|
anime();
|
|
};
|
|
|