Vue implements a simple marquee effect

Vue implements a simple marquee effect

This article shares the specific code of Vue to achieve a simple marquee effect for your reference. The specific content is as follows

Rendering

Code

html

<div id="app">
    <button @click="start">Start</button>
    <button @click="stop">Stop</button>
    <p>{{msg}}</p>
</div>

vue

var app = new Vue({
    el: "#app", // indicates that the new vue instance we are creating now will control the area on the page // data is the m in mvvm, which is used to store the data of each page data:{
        msg: "Lock on Li Jiaqi's live broadcast room at 19:30 tonight, don't miss it~",
        timer: null
    },
    methods:{
        start(){
            // Use the timer text to scroll on time // Arrow function can solve the this pointing problem // The this pointing in the arrow function is consistent with that outside the function // The timer is turned on only when timer is not null if (this.timer != null) return;
            this.timer = setInterval(() => {
                // Get the first character var startMsg = this.msg.substring(0,1);
                // Get all the characters that follow var endMsg = this.msg.substring(1);
                // Reassemble msg
                this.msg = endMsg + startMsg;
            },400)
        },

        stop(){
            clearInterval(this.timer);
            // You can print the timer after clearing the timer yourself, and you will find that it is not null, so you need to reassign this.timer = null;
        }
    }
});

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Text Marquee Component Based on Vue (npm Component Package)
  • Vue implements simple marquee effect
  • Vue achieves seamless carousel effect (marquee)
  • Vue implements horizontal scrolling of marquee style text
  • Vue implements the marquee effect
  • Vue realizes simple effect of running light
  • Vue example code using timer to achieve marquee effect
  • Vue implements a simple marquee
  • Js and VUE to achieve the marquee effect
  • Detailed explanation of how to use the Vue marquee component

<<:  Examples of common Nginx misconfigurations

>>:  How to extract string elements from non-fixed positions in MySQL

Recommend

MySQL slow query: Enable slow query

1. What is the use of slow query? It can record a...

js object to achieve data paging effect

This article example shares the specific code of ...

How to use physics engine joints in CocosCreator

Table of contents mousejoint mouse joint distance...

mysql8.0.23 linux (centos7) installation complete and detailed tutorial

Table of contents What is a relational database? ...

Summary of methods for querying MySQL user permissions

Introduce two methods to view MySQL user permissi...

Explain how to analyze SQL efficiency

The Explain command is the first recommended comm...

Detailed explanation of three ways to wrap text in el-table header

Table of contents Problem Description Rendering T...

MySQL database JDBC programming (Java connects to MySQL)

Table of contents 1. Basic conditions for databas...

Summary of the differences between MySQL storage engines MyISAM and InnoDB

1. Changes in MySQL's default storage engine ...

How to write high-quality JavaScript code

Table of contents 1. Easy to read code 1. Unified...

Use of Linux watch command

1. Command Introduction The watch command execute...

centos 7 modify sshd | prohibit root login and sshd port script definition

1. Create a new user wwweee000 [root@localhost ~]...