<script>
let animationId = ''
created() {
animationId = requestAnimationFrame(this.wormMotion());
},
methond{
//开始计算
wormMotion() {
const step = () => {
//逻辑
if (this.wormX < -500) {
this.wormX = -500
} else {
this.wormX -= 2.5;
this.seletWorm.forEach((v, i) => {
this.seletWorm[i].X -= 2.5
this.$nextTick(() => {
this.getElementPosition()
})
})
};
//以上是你自己的逻辑处理
animationId = requestAnimationFrame(step);
}
step()
},
// 停止动画
stopAnimation() {
if (animationId) {
cancelAnimationFrame(animationId);
animationId = null;
}
},
// 再次开始动画
startAnimation() {
if (!animationId) {
animationId = requestAnimationFrame(this.wormMotion());
}
},
}
</script>
02-05
661
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)