修改为js显示效果,利用transform
标签中动态增加移动百分比默认textLeft 为0:
<text :style="{transform : 'translateX(-' + textLeft + '%)'} "></text>
创建移动递归方法:
tipsfun(){
var that = this;
//根据需求进入页面停顿3秒后开始移动
setTimeout(()=>{
//data中接收setInterval事件
that.timeInterval = setInterval(()=>{
//判断如果textLeft大于等于100,说明移动完毕。需要归0,重新移动。
if(that.textLeft >= 100){
that.textLeft = 0
//清除data中的setInterval事件
clearInterval(that.timeInterval)
//再次递归调用tipsfun方法,实现无限循环
that.tipsfun()
return
}
//控制每次移动的距离
that.textLeft+=0.1
//控制多久移动一次
},15)
//设置每次结束后距离下次移动中间停顿的时间
},3000)
},
在onUnload关闭页面清除定时事件:
onUnload() {
// 清除定时器
clearInterval(this.timeInterval)
},