WeChat applet achieves the text running lamp effect, and Applet text running lamp

Source: Internet
Author: User

The small program achieves the text running lamp effect, and the small program text running lamp

This article provides examples to share with you the specific code of the small program to implement the text marquee for your reference. The specific content is as follows:

Effect

 

Wxml

<View> 1. display it again </view> <view class = "example"> <view class = "marquee_box"> <view class = "marquee_text" style = "{ {orientation }}: {marqueeDistance} px; font-size: {size} px; ">{{ text }}</view> <view> 2 is displayed after a white edge appears </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>

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. jsPage ({data: {text: 'This is a rolling text running lantern, hahahahahahahahahaha', marqueePace: 1, // rolling speed marqueeDistance: 0, // The initial rolling distance is marqueeDistance2: 0, marquee2copy_status: false, marquee2_margin: 60, size: 14, orientation: 'left', // interval: 20 // time interval }, onShow: function () {// The page displays var vm = this; var length = vm. data. text. length * vm. data. size; // text length var 1_wwidth = wx. getSystemInfo Sync (). interval wwidth; // screen width vm. setData ({length: length, interval wwidth: interval wwidth, marquee2_margin: length <interval wwidth? Required wwidth-length: vm. data. marquee2_margin // when the text length is smaller than the screen length, add a whitelist}); vm. run1 (); // scroll the vm in the original direction after a horizontal row of words is finished. run2 (); // immediately appears from the right after the first word disappears}, 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. required wwidth}); vm. run1 () ;}}, vm. data. interval) ;}, run2: function () {var vm = this; var interval = setInterval (function () {if (-vm. data. marqueeDistance2 <vm. data. length) {// if the text is scrolled to the white edge with marquee2_margin = 30px, the vm is displayed. setData ({marqueeDistance2: vm. data. marqueeDistance2-vm. data. marqueePace, marquee2copy_status: vm. data. length + vm. data. marqueeDistance2 <= vm. data. required wwidth + vm. data. marquee2_margin,});} else {if (-vm. data. marqueeDistance2> = vm. data. marquee2_margin) {// vm when the second text is scrolled to the leftmost. setData ({marqueeDistance2: vm. data. marquee2_margin // directly scroll back}); clearInterval (interval); vm. run2 ();} else {clearInterval (interval); vm. setData ({marqueeDistance2:-vm. data. required wwidth}); vm. run2 () ;}}, vm. data. interval );}})

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.