Mini Program to Implement Text Circular Scrolling Animation

Mini Program to Implement Text Circular Scrolling Animation

This article shares the specific code of the applet to realize the text loop scrolling through examples for your reference. The specific content is as follows

Solving the problem:

1. Text loop playback effect

2. Exit the applet and stop the hidden background animation (solved)

Effect:

Code:

wxml

<view animation="{{animation}}" class="animation">
  919 test use - small program loop playback~~~
</view>

wxss

.animation{
  width: 100%;
  transform: translateX(100%);
  position: fixed;
  top: 45%;
  font-size: 16px;
  font-weight: bold;
}

Final js

/**
   * Life cycle function - listen for the completion of the initial rendering of the page*/
  onReady: function () {
    this.bindAnimation();
  },
 
  bindAnimation(){
    var this_ = this;
      var animation = wx.createAnimation({
        duration: 5000,
        timingFunction: 'linear',
        transformOrigin:"100% 0 0"
      })
      animation.translateX('-100%').step();
      this.setData({
        animation:animation.export(),
      })
      //Set up loop animation this.animation = animation;
      setInterval(function(){
        //The second animation text position initialization this.Animation2();
 
        // Delay the scrolling animation (the effect will be better)
        setTimeout(function(){
          this.animation.translateX('-100%').step();
          this.setData({
            animation: animation.export(),
          })
        }.bind(this),200);
 
        
      }.bind(this),5000);
 
  },
 
  /**
   * Initialize the second animation text position*/
  Animation2(){
    var this_ = this;
    var animation2 = wx.createAnimation({
      duration: 0,
      timingFunction: 'linear',
      transformOrigin:"100% 0 0"
    })
    animation2.translateX('100%').step();
    this_.setData({
      animation:animation2.export(),
    })
  },
 
  /**
   * Solve the problem of mini program exit and background animation stopping */
  onHide: function () {
    //Solve the problem of mini program exit and background animation stopping //Re-trigger the animation method this.bindAnimation();
},

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:
  • How to start and pause the loop animation of the mpvue applet
  • WeChat applet realizes looping animation effect
  • WeChat applet development animation loop animation to achieve the effect of floating clouds

<<:  Detailed explanation of MySQL execution principle, logical layering, and changing database processing engine

>>:  Tutorial on installing Docker in Windows 10 subsystem Ubuntu (WSL) (with pictures and text)

Recommend

Vue+echart realizes double column chart

This article shares the specific code of vue+echa...

This article helps you understand PReact10.5.13 source code

Table of contents render.js part create-context.j...

In-depth analysis of MySQL query interception

Table of contents 1. Query Optimization 1. MySQL ...

How to add color mask to background image in CSS3

Some time ago, during development, I encountered ...

How to build Jenkins+Maven+Git continuous integration environment on CentOS7

This article takes the deployment of Spring boot ...

Nginx server https configuration method example

Linux: Linux version 3.10.0-123.9.3.el7.x86_64 Ng...

Solution to Django's inability to access static resources with uwsgi+nginx proxy

When deploying uwsgi+nginx proxy Django, access u...

Full steps to create a password generator using Node.js

Table of contents 1. Preparation 2. Writing comma...

Summary of Button's four Click response methods

Button is used quite a lot. Here I have sorted ou...

How to configure nginx to return text or json

Sometimes when requesting certain interfaces, you...

js implements a simple English-Chinese dictionary

This article shares the specific code of js to im...

Mysql anonymous login cannot create a database problem solution

Frequently asked questions Access denied for user...

10 Underused or Misunderstood HTML Tags

Here are 10 HTML tags that are underused or misun...