1. 程式人生 > >Vue 文字跑馬燈效果

Vue 文字跑馬燈效果

1. 話不多說 看程式碼

在這裡插入圖片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue-2.5.17.js"></script>
  


</head>
<body>

<div id="app">

   <input type="button" value="開始"  v-bind:
disabled
=isDisabl @click="start">
<input type="button" value="結束" @click="stop"> <br> {{good}} </div> <script> new Vue({ el: "#app", data: { good: "好好學習,天天向上!!!", interval: null, isDisabl:false }
, methods: { start() { console.log(this.good); var _this = this; _this.interval = setInterval(function () { //獲取第一個字元 var start = _this.good.substring(0, 1); //得到後面的字元 var
end = _this.good.substring(1); _this.isDisabl=true; //重新賦值 _this.good = end + start; }, 400) }, stop: function () { //停止計時器 this.isDisabl=false; clearInterval(this.interval); } } })
</script> </body> </html>