Skip to content

Commit 8e406ae

Browse files
committed
fix: reset loopCount state
1 parent 5559e94 commit 8e406ae

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/countup.vue

+7-8
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,15 @@ const initCountUp = () => {
5757
}
5858
emits('init', countUp.value)
5959
}
60-
let loopCount = 0
6160
// 开始动画
6261
const startAnim = () => {
6362
countUp.value?.start()
64-
loopCount++
6563
checkAnimateState()
6664
}
6765
// 循环动画
66+
let loopCount = 1
6867
const loopAnim = () => {
6968
loopCount++
70-
// console.log('loop', loopCount)
7169
finished.value = false
7270
countUp.value?.reset()
7371
startAnim()
@@ -78,7 +76,7 @@ let timerId: number
7876
const checkAnimateState = () => {
7977
clearTimeout(timerId)
8078
timerId = window.setTimeout(() => {
81-
// console.log('check');
79+
// console.log('check')
8280
finished.value = countUp.value?.frameVal == props.endVal
8381
if (!finished.value) {
8482
checkAnimateState()
@@ -88,12 +86,13 @@ const checkAnimateState = () => {
8886
watch(finished, (flag) => {
8987
if (!flag) return
9088
// console.log('finished', flag)
89+
// console.log('loop', loopCount)
9190
emits('finished')
9291
const isBool = typeof props.loop === 'boolean'
93-
if (props.loop) {
94-
if (isBool || props.loop > loopCount) {
95-
loopAnim()
96-
}
92+
if ((isBool && props.loop) || props.loop > loopCount) {
93+
loopAnim()
94+
} else {
95+
loopCount = 1
9796
}
9897
})
9998

0 commit comments

Comments
 (0)