1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>个人界面</title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="text"> <input type="button" value="开始效果" :title="beginTitle" @click="begin"> <input type="button" value="停止效果" :title="endTitle" @click="ends"> <br> {{msg}} </div> <script> const vm = new Vue({ el: "#text", data: { msg: "跑马灯效果展示...", beginTitle: "开始展示效果", endTitle: "停止效果展示", intervalID: null }, methods: { begin: function () {
if (this.intervalID == null) { this.intervalID = setInterval(() => { this.msg = this.msg.substring(1) + this.msg.substring(0, 1); }, 300); } }, ends() { clearInterval(this.intervalID); this.intervalID = null; this.msg = "跑马灯效果展示..."; } } }) ; </script> </body> </html>
|