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

Nginx builds rtmp live server implementation code

1. Create a new rtmp directory in the nginx sourc...

JavaScript removes unnecessary properties of an object

Table of contents Example Method 1: delete Method...

Summary of tips for setting the maximum number of connections in MySQL

Method 1: Command line modification We only need ...

Detailed explanation of CSS line-height and height

Recently, when I was working on CSS interfaces, I...

HTML discount price calculation implementation principle and script code

Copy code The code is as follows: <!DOCTYPE HT...

How to operate MySQL database with ORM model framework

What is ORM? ORM stands for Object Relational Map...

In-depth explanation of Session and Cookie in Tomcat

Preface HTTP is a stateless communication protoco...

How to install tomcat8 in docker

1. Install tomcat8 with docker 1. Find the tomcat...

IE8 Developer Tools Menu Explanation

<br />This article has briefly explained the...

Detailed explanation of moment.js time and date processing

Monday to Sunday time format conversion (Y --- ye...

Simple usage example of MySQL 8.0 recursive query

Preface This article uses the new features of MyS...