diff --git a/src/components/scrollBoard/src/main.vue b/src/components/scrollBoard/src/main.vue index bec3fd6..15f26b1 100644 --- a/src/components/scrollBoard/src/main.vue +++ b/src/components/scrollBoard/src/main.vue @@ -161,7 +161,9 @@ export default { animationIndex: 0, - animationHandler: '' + animationHandler: '', + + updater: 0 } }, watch: { @@ -304,7 +306,7 @@ export default { this.aligns = deepMerge(aligns, align) }, async animation (start = false) { - let { avgHeight, animationIndex, mergedConfig, rowsData, animation } = this + let { avgHeight, animationIndex, mergedConfig, rowsData, animation, updater } = this const { waitTime, carousel, rowNum } = mergedConfig @@ -312,7 +314,10 @@ export default { if (rowNum >= rowLength) return - if (start) await new Promise(resolve => setTimeout(resolve, waitTime)) + if (start) { + await new Promise(resolve => setTimeout(resolve, waitTime)) + if (updater !== this.updater) return + } const animationNum = carousel === 'single' ? 1 : rowNum @@ -323,6 +328,7 @@ export default { this.heights = new Array(rowLength).fill(avgHeight) await new Promise(resolve => setTimeout(resolve, 300)) + if (updater !== this.updater) return this.heights.splice(0, animationNum, ...new Array(animationNum).fill(0)) @@ -335,7 +341,9 @@ export default { this.animationHandler = setTimeout(animation, waitTime - 300) }, stopAnimation () { - const { animationHandler } = this + const { animationHandler, updater } = this + + this.updater = (updater + 1) % 999999 if (!animationHandler) return diff --git a/src/components/scrollRankingBoard/src/main.vue b/src/components/scrollRankingBoard/src/main.vue index 4df1823..320a593 100644 --- a/src/components/scrollRankingBoard/src/main.vue +++ b/src/components/scrollRankingBoard/src/main.vue @@ -89,7 +89,9 @@ export default { animationIndex: 0, - animationHandler: '' + animationHandler: '', + + updater: 0 } }, watch: { @@ -172,7 +174,7 @@ export default { if (!onresize) this.heights = new Array(data.length).fill(avgHeight) }, async animation (start = false) { - let { avgHeight, animationIndex, mergedConfig, rowsData, animation } = this + let { avgHeight, animationIndex, mergedConfig, rowsData, animation, updater } = this const { waitTime, carousel, rowNum } = mergedConfig @@ -180,7 +182,10 @@ export default { if (rowNum >= rowLength) return - if (start) await new Promise(resolve => setTimeout(resolve, waitTime)) + if (start) { + await new Promise(resolve => setTimeout(resolve, waitTime)) + if (updater !== this.updater) return + } const animationNum = carousel === 'single' ? 1 : rowNum @@ -191,6 +196,7 @@ export default { this.heights = new Array(rowLength).fill(avgHeight) await new Promise(resolve => setTimeout(resolve, 300)) + if (updater !== this.updater) return this.heights.splice(0, animationNum, ...new Array(animationNum).fill(0)) @@ -203,7 +209,9 @@ export default { this.animationHandler = setTimeout(animation, waitTime - 300) }, stopAnimation () { - const { animationHandler } = this + const { animationHandler, updater } = this + + this.updater = (updater + 1) % 999999 if (!animationHandler) return