This article mainly introduces the text marquee effect of WeChat applet in detail. It has certain reference value. Interested friends can refer to it.
The example of this article is to share with everyone the WeChat applet effect. The specific code of the program to implement the text ticker is for your reference. The specific content is as follows
Effect
wxml
<view>1 显示完后再显示</view> <view class="example"> <view class="marquee_box"> <view class="marquee_text" style="{{orientation}}:{{marqueeDistance}}px;font-size: {{size}}px;"> {{text}} </view> </view> </view> <view>2 出现白边后即显示</view> <view class="example"> <view class="marquee_box"> <view class="marquee_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; } .marquee_box { width: 100%; position: relative; } .marquee_text { white-space: nowrap; position: absolute; top: 0; }
js
// pages/home/marquee/marquee.js Page({ data: { text: '这是一条会滚动的文字滚来滚去的文字跑马灯,哈哈哈哈哈哈哈哈', marqueePace: 1,//滚动速度 marqueeDistance: 0,//初始滚动距离 marqueeDistance2: 0, marquee2copy_status: false, marquee2_margin: 60, size: 14, orientation: 'left',//滚动方向 interval: 20 // 时间间隔 }, onShow: function () { // 页面显示 var vm = this; var length = vm.data.text.length * vm.data.size;//文字长度 var windowWidth = wx.getSystemInfoSync().windowWidth;// 屏幕宽度 vm.setData({ length: length, windowWidth: windowWidth, marquee2_margin: length < windowWidth ? windowWidth - length : vm.data.marquee2_margin//当文字长度小于屏幕长度时,需要增加补白 }); vm.run1();// 水平一行字滚动完了再按照原来的方向滚动 vm.run2();// 第一个字消失后立即从右边出现 }, 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) { // 如果文字滚动到出现marquee2_margin=30px的白边,就接着显示 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) { // 当第二条文字滚动到最左边时 vm.setData({ marqueeDistance2: vm.data.marquee2_margin // 直接重新滚动 }); clearInterval(interval); vm.run2(); } else { clearInterval(interval); vm.setData({ marqueeDistance2: -vm.data.windowWidth }); vm.run2(); } } }, vm.data.interval); } })
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to implement the longest common subsequence in javascript
How to get the file upload progress in Node.js ?
Why will Node.js become a web application development?
The above is the detailed content of How to achieve text marquee effect in WeChat mini program. For more information, please follow other related articles on the PHP Chinese website!

本篇文章给大家带来了关于微信小程序的相关问题,其中主要介绍了关于基础架构原理的相关内容,其中包括了宿主环境、执行环境、小程序整体架构、运行机制、更新机制、数据通信机制等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于微信小程序的相关知识,其中主要介绍了关于云服务的配置详解,包括了创建使用云开发项目、搭建云环境、测试云服务等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于微信小程序的相关知识,其中主要介绍了关于富文本编辑器的实战示例,包括了创建发布页面、实现基本布局、实现编辑区操作栏的功能等内容,下面一起来看一下,希望对大家有帮助。

西安坐地铁用的小程序为“乘车码”。使用方法:1、打开手机微信客户端,点击“发现”中的“小程序”;2、在搜索栏中输入“乘车码”进行搜索;3、直接定位城市西安,或者搜索西安,点击“西安地铁乘车码”选项的“去乘车”按钮;4、根据腾讯官方提示进行授权,开通“乘车码”业务即可利用该小程序提供的二维码来支付乘车了。

本篇文章给大家带来了关于微信小程序的相关问题,其中主要介绍了关于开发工具介绍的相关内容,包括了下载开发工具以及编辑器总结等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于微信小程序的相关知识,其中主要介绍了怎么实现小程序授权登录功能的相关内容,下面一起来看一下,希望对大家有帮助。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
