<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./vue.min.js"></script>
</head>
<body>
<div id="app">
<button @click="move">动动动</button>
<button @click="stop">停停停</button>
<div>{{msg}}</div>
</div>
<script>
var vm = new Vue({
el:'#app',
data:{
msg:'关关雎鸠',
intervalId:null
},
methods:{
move(){
if(this.intervalId!=null)return;
this.intervalId = setInterval(()=>{
//截取第一位
let start =this.msg.substring(0,1)
//截取第二位到最后
let end =this.msg.substring(1)
this.msg = end+start
},400)
},
stop(){
clearInterval(this.intervalId)
this.intervalId = null
}
}
})
</script>
</body>
</html>
使用Vue制作跑马灯效果!
最新推荐文章于 2024-07-22 09:29:57 发布