Vue实现滚动字条/跑马灯,供大家参考,具体内容如下
内容不多,直接看代码吧
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < title >Title</ title > < script src = "../../资料/js/vue.js" ></ script > <!-- 引入Vue--> </ head > < style > *{ text-align: center; } </ style > < body > < div id = "app" > < h1 >{{txt}}</ h1 > < button @ click = "run" >开始</ button > < button @ click = "stop" >停止</ button > </ div > </ body > </ html > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <script> new Vue({ el: '#app' , data:{ txt: "吾疑君驭车而飚之,然苦于无证以示众。" , timer: null }, methods:{ run(){ if ( this .timer != null ){ return ; } this .timer = setInterval(()=>{ let start = this .txt.substring(0,1); //截取下标为0的字符串 let end = this .txt.substring(1); //截取从下标为1到结束的字符串 this .txt = end + start; },300); }, stop(){ clearInterval( this .timer) } } }) </script> |
效果如下图:
关于vue.js组件的教程,请大家点击专题vue.js组件学习教程进行学习。
更多vue学习教程请阅读专题《vue实战教程》
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持因特网 www.inte.net 。