This commit is contained in:
joylink_cuiweidong 2022-09-28 14:13:56 +08:00
commit f58cdd4f1c

View File

@ -37,6 +37,7 @@ export default {
},
mounted() {
this.initAnimation()
window.addEventListener('visibilitychange', this.visibilityChangeHandler)
},
methods: {
initAnimation() {
@ -49,7 +50,14 @@ export default {
this.currentIndex = this.nextIndex(this.currentIndex)
}
}, 1000)
}, 3000)
}, 4000)
},
pauseAnimation() {
clearInterval(timer)
},
visibilityChangeHandler() {
if (document.hidden) this.pauseAnimation()
else this.initAnimation()
},
nextIndex(idx) {
return idx < this.len - 1 ? idx + 1 : 0
@ -57,6 +65,7 @@ export default {
},
beforeDestroy() {
timer = null
window.removeEventListener('visibilitychange', this.visibilityChangeHandler)
},
}
</script>