Vue realizes simple effect of running light

Vue realizes simple effect of running light

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

1. Marquee effect

Description: Click the "Support" button to make the text float to the left, then click the "Pause" button to stop the current floating

2. Complete code (Note: the vue.js file needs to be introduced in the code. This file is introduced according to the directory location. The specific location is commented in the code)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Marquee</title>
    <!-- Import vue.js file-->
    <script src="../vue.js"></script>
 <style type="text/css">
  #app{
   padding: 20px;
  }
 </style>
</head>
<body>
<div id="app">
    <button @click="run">Support</button>
    <button @click="stop">Pause</button>
 <h3>{{msg}}</h3>
</div>
<script>
    new Vue({
        el:"#app",
        data:{
            msg:"Friends, friends, I love you, just like mice love rice~~~!",
            timer:null //Define the timer on data, the default value is null
        },
        methods:{
            run(){
    // If timer has been assigned, return if(this.timer){return};
                this.timer = setInterval(() => {
     // msg is split into arrays var arr = this.msg.split('');
     // shift deletes and returns the deleted one, push adds to the end // put the first element of the array at the end arr.push(arr.shift());
     // arr.join('') connects the array into a string and copies it to msg
     this.msg = arr.join('');
                },100)
            },
            stop(){
                //Clear timer clearInterval(this.timer);
                //After clearing the timer, you need to set the timer to null again
                this.timer = null;
            }
        }
    })
</script>
</body>
</html>

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 example code using timer to achieve marquee effect
  • Vue implements a simple marquee
  • Js and VUE to achieve the marquee effect
  • Vue implements a simple marquee effect
  • Detailed explanation of how to use the Vue marquee component

<<:  Each time Docker starts a container, the IP and hosts specified operations

>>:  MySQL online DDL tool gh-ost principle analysis

Recommend

How to build lnmp environment in docker

Create a project directory mkdir php Create the f...

How to use VirtualBox to build a local virtual machine environment on Mac

1. Big Data and Hadoop To study and learn about b...

Detailed explanation of Angular component life cycle (I)

Table of contents Overview 1. Hook calling order ...

Summary of the benefits of deploying MySQL delayed slaves

Preface The master-slave replication relationship...

How to correctly modify the ROOT password in MySql8.0 and above versions

Deployment environment: Installation version red ...

How to install MySQL for beginners (proven effective)

1. Software Download MySQL download and installat...

Tutorial on building svn server with docker

SVN is the abbreviation of subversion, an open so...

Div nested html without iframe

Recently, when doing homework, I needed to nest a ...

How to authorize all the contents of a folder to a certain user in Linux?

【Problem Analysis】 We can use the chown command. ...

Introduction to the method attribute of the Form form in HTML

1 method is a property that specifies how data is ...

Introduction to MySQL isolation level, lock and MVCC

This article aims to clarify the relationship bet...

A brief analysis of the differences between undo, redo and binlog in MySQL

Table of contents Preface 【undo log】 【redo log】 【...

40 fonts recommended for famous website logos

Do you know what fonts are used in the logo desig...