mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
feat(Circle): using setTimeout instead of setInterval (#4401)
This commit is contained in:
parent
e07f9f9581
commit
41457c899b
@ -181,27 +181,31 @@ VantComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clearInterval();
|
this.clearMockInterval();
|
||||||
this.currentValue = this.currentValue || 0;
|
this.currentValue = this.currentValue || 0;
|
||||||
this.interval = setInterval(() => {
|
const run = () => {
|
||||||
if (this.currentValue !== value) {
|
this.interval = setTimeout(() => {
|
||||||
if (Math.abs(this.currentValue - value) < STEP) {
|
if (this.currentValue !== value) {
|
||||||
this.currentValue = value;
|
if (Math.abs(this.currentValue - value) < STEP) {
|
||||||
} else if (this.currentValue < value) {
|
this.currentValue = value;
|
||||||
this.currentValue += STEP;
|
} else if (this.currentValue < value) {
|
||||||
|
this.currentValue += STEP;
|
||||||
|
} else {
|
||||||
|
this.currentValue -= STEP;
|
||||||
|
}
|
||||||
|
this.drawCircle(this.currentValue);
|
||||||
|
run();
|
||||||
} else {
|
} else {
|
||||||
this.currentValue -= STEP;
|
this.clearMockInterval();
|
||||||
}
|
}
|
||||||
this.drawCircle(this.currentValue);
|
}, 1000 / speed);
|
||||||
} else {
|
};
|
||||||
this.clearInterval();
|
run();
|
||||||
}
|
|
||||||
}, 1000 / speed);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
clearInterval() {
|
clearMockInterval() {
|
||||||
if (this.interval) {
|
if (this.interval) {
|
||||||
clearInterval(this.interval);
|
clearTimeout(this.interval);
|
||||||
this.interval = null;
|
this.interval = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -216,6 +220,6 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
destroyed() {
|
destroyed() {
|
||||||
this.clearInterval();
|
this.clearMockInterval();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user