WeChat applet implements text scrolling

WeChat applet implements text scrolling

This article example shares the specific code for WeChat applet to implement text scrolling for your reference. The specific content is as follows

wxml:

<view>After displaying, display again:</view>
<view class="example">
 <view class="box">
 <view class="text" style="{{orientation}}:{{marqueeDistance}}px;font-size: {{size}}px;">
  {{text}}
 </view>
 </view>
</view>
<view>When the white border appears, it will display:</view>
<view class="example">
 <view class="box">
 <view class="text" style="{{orientation}}:{{marqueeDistance2}}px;font-size: {{size}}px;">
  <text>{{text}}</text>
  <text wx:if="{{marquee2copy_status}}" style="margin-left:{{marquee2_margin}}px;">{{text}}</text>
 </view>
 </view>
</view>

wxss:

.example {
 display: block;
 width: 100%;
 height: 100rpx;
}

.box {
 width: 100%;
 position: relative;
}

.text {
 white-space: nowrap;
 position: absolute;
 top: 0;
}

js:

Page({


 data: {
 text: 'Scrolling text 1234567890abcdefghijklmnopqrstuvmxyz',
 marqueePace: 1, //Scrolling speed marqueeDistance: 0, //Initial scrolling distance marqueeDistance2: 0,
 marquee2copy_status: false,
 marquee2_margin: 60,
 size: 14,
 orientation: 'left', //Scroll direction interval: 20 // Time interval},
 onShow: function() {
 // Page display var vm = this;
 var length = vm.data.text.length * vm.data.size; //text length var windowWidth = wx.getSystemInfoSync().windowWidth; //screen width vm.setData({
  length: length,
  windowWidth: windowWidth,
  marquee2_margin: length < windowWidth ? windowWidth - length : vm.data.marquee2_margin //When the text length is shorter than the screen length, padding needs to be added});
 vm.run1(); //After scrolling a horizontal line of words, scroll in the original direction vm.run2(); //The first word disappears and then immediately appears from the right },
 run1: function() {
 var vm = this;
 var interval = setInterval(function() {
  if (-vm.data.marqueeDistance < vm.data.length) {
  vm.setData({
   marqueeDistance: vm.data.marqueeDistance - vm.data.marqueePace,
  });
  } else {
  clearInterval(interval);
  vm.setData({
   marqueeDistance: vm.data.windowWidth
  });
  vm.run1();
  }
 }, vm.data.interval);
 },
 run2: function() {
 var vm = this;
 var interval = setInterval(function() {
  if (-vm.data.marqueeDistance2 < vm.data.length) {
  // If the text scrolls to the white edge of marquee2_margin=30px, then display vm.setData({
   marqueeDistance2: vm.data.marqueeDistance2 - vm.data.marqueePace,
   marquee2copy_status: vm.data.length + vm.data.marqueeDistance2 <= vm.data.windowWidth + vm.data.marquee2_margin,
  });
  } else {
  if (-vm.data.marqueeDistance2 >= vm.data.marquee2_margin) { // When the second text scrolls to the leftmost vm.setData({
   marqueeDistance2: vm.data.marquee2_margin // re-roll directly });
   clearInterval(interval);
   vm.run2();
  } else {
   clearInterval(interval);
   vm.setData({
   marqueeDistance2: -vm.data.windowWidth
   });
   vm.run2();
  }
  }
 }, vm.data.interval);
 }


})

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:
  • WeChat applet scroll-view hidden scroll bar detailed explanation
  • How to implement scroll penetration and prevent scrolling in WeChat applet scroll-view
  • Detailed explanation of the practical pitfalls of WeChat applet scroll-view horizontal scrolling and the implementation of hiding its scroll bar
  • WeChat applet top scrollable navigation effect
  • WeChat applet scroll-view component implements scrolling animation
  • WeChat applet-example code for scrolling message notification
  • WeChat applet scroll tab to achieve left and right sliding switching
  • WeChat applet realizes multi-line text scrolling effect
  • WeChat applet realizes horizontal and vertical scrolling
  • WeChat Mini Programs Achieve Seamless Scrolling

<<:  How to show or hide common icons on the desktop in Windows Server 2012

>>:  my.cnf parameter configuration to optimize InnoDB engine performance

Recommend

9 ways to show and hide CSS elements

In web page production, displaying and hiding ele...

Introduction to the process of installing MySQL 8.0 in Linux environment

Table of contents Preface 1. Linux changes the yu...

MySQL optimization: use join instead of subquery

Use JOIN instead of sub-queries MySQL supports SQ...

Detailed explanation of the use of custom parameters in MySQL

MySQL variables include system variables and syst...

Example of downloading files with vue+django

Table of contents 1. Overview 2. Django Project 3...

Vue implements fuzzy query-Mysql database data

Table of contents 1. Demand 2. Implementation 3. ...

Detailed explanation of mandatory and implicit conversion of types in JavaScript

Table of contents 1. Implicit conversion Conversi...

Vue Element-ui table realizes tree structure table

This article shares the specific code of Element-...

Detailed graphic tutorial on installing and uninstalling Tomcat8 on Linux

[ Linux installation of Tomcat8 ] Uninstall Tomca...

Linux Dig command usage

Dig Introduction: Dig is a tool that queries DNS ...

Detailed explanation of four solutions to floating problems in CSS layout

1. Cause: The effect after the subbox is set to f...

Vue project code splitting solution

Table of contents background Purpose Before split...

Tutorial on installing and using virtualenv in Deepin

virtualenv is a tool for creating isolated Python...

The difference between MySQL database host 127.0.0.1 and localhost

Many of my friends may encounter a problem and do...