欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue跑马灯效果.html

程序员文章站 2022-07-14 21:33:42
...

 代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>跑马灯</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <input type="button" value="浪起来" @click="lang">
    <input type="button" value="低调" @click="stop">
    <h4>{{msg}}</h4>
</div>
<script>
var vm = new Vue({
    el: '#app',
    data: {
        msg: '猥琐发育,别浪~!一直循环吧',
        intervalId: null
    },
    methods: {
        lang() {
            if (this.intervalId != null) return;
            this.intervalId = setInterval(() => {
                var start = this.msg.substring(0, 1);
                var end = this.msg.substring(1);
                this.msg = end + start;
            }, 400)
        },
        stop() {
            clearInterval(this.intervalId);
            this.intervalId = null;
        }
    }
})
</script>
</body>
</html>

vue跑马灯效果.html

解析:

 

vue跑马灯效果.html

 

vue跑马灯效果.html

vue跑马灯效果.html

 

相关标签: vuejs