Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize text scrolling with vuejs

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to achieve text scrolling in vuejs". In daily operation, I believe many people have doubts about how to achieve text scrolling in vuejs. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to achieve text scrolling in vuejs". Next, please follow the editor to study!

Vuejs to achieve text scrolling methods: 1, create a good front-end code file; 2, through the js code to control the height of the box, and make it repeatedly added.

This article operating environment: windows7 system, vue2.9.6 version, DELL G3 computer.

How does vuejs achieve text scrolling?

VueJS and Javascript achieve the effect of scrolling text up and down:

When it comes to scrolling text up and down, we think of using different programs to achieve it, and having text scrolling in the page will increase the interaction and credibility of the page.

The easiest way to 1.Js is to control the height of the box so that it can be added repeatedly.

/ * * scroll css**/#scrolldiv {height: 400pxSingapore: hidden } the user 130 dollars has just hit 500 yuan and the Jingdong card is in the process of redemption. the user 176 dollars 2746 has just hit 1000 U.S. dollars as a gift and the user 132 dollars 7754 has just hit 500 yuan. User 181 hit USB drive 4518 minutes ago + portable battery is redeeming user 185 minutes ago hit brand hot-selling thermos cup is exchanging user 158 minutes ago hit foreign exchange trading book + premium Umbrella + mobile phone bracket + hippocampal knife is in the process of redemption. The user hit US $1000 3 minutes ago and the gift money was successfully exchanged for 170,0,437 minutes ago. U disk + advanced pen + portable battery has been successfully exchanged for 156RMB dollars for 24755 minutes. The former hit the brand hot-selling thermal insulation cup has been successfully exchanged for the user 18900RMB 1698 7 minutes ago, the Jingdong card has been successfully exchanged for the user 132mpg, 1754 us dollars, 8 minutes ago, the gift money has been successfully exchanged for 177mpg, 2154, 9 minutes ago Foreign exchange trading book + advanced umbrella + mobile phone bracket + hippocampal knife has been successfully exchanged / * * word scroll css**/ _ window.onload = roll (40) Function roll (t) {var scroll1 = document.getElementById ("scroll1"); var scroll2= document.getElementById ("scroll2"); var scrolldiv = document.getElementById ("scrolldiv"); / / copy the content repeatedly to achieve a continuous scrolling effect: scroll2 [XSS _ clean] = scroll1 [XSS _ clean]; scrolldiv.scrollTop = 0; setInterval (rollStart, t) } function rollStart () {if (scrolldiv.scrollTop > = scroll1.scrollHeight) {scrolldiv.scrollTop = 0;} else {scrolldiv.scrollTop++;}}

Scrolling the text online with 2.Vuejs

The front-end code is rendered:

{{item.time}} {{randomPhoneNumber ()}} user diagnosed {{item.company}}

Data structure design:

New Vue ({el:'#app', data () {return {animate:false, scroll_lists: [{time:'2 seconds ago, company:' Haekangwei (002415)'}, {time:'8 seconds ago', company:' FiberHome Communications (600498)'}, {time:'3 minutes ago' Company:' Hengyi Petrochemical (000703)'}, {time:'5 minutes ago', company:' Ziguang Weiwei (002049)'}, {time:'39 minutes ago', company:' Xintian Technology (300259)'}, {time:'1 hours ago', company:' Societe Generale Bank (601166)'}, {time:'3 hours ago' Company:' China Nuclear Construction (601611)'}],} }, / / created: called before the template is rendered to html, that is, some property values are usually initialized and then rendered into a view. / / mounted: called after the template is rendered to html, usually after the initialization page is completed, and then perform some necessary operations on the dom node of html. Created () {setInterval (this.scroll,2000)}, methods: {/ / generate the random sequence randomCode:function (len,dict) {for (var I = 0 len; rs =''; I < len; I +) rs + = dict.charAt (Math.floor (Math.random () * 100000000)% dict.length); return rs }, / / generate random mobile phone number randomPhoneNumber:function () {/ / bit 1 is 1, bit 2, bit 3 is bit 4-7 is * the last four digits of random this.$options.methods use the return value of the previous function return [1 ~ *, this.$options.methods.randomCode (4 ~ 12 ~ 3456789')] .join (') }, scroll () {this.animate = true var that = this; setTimeout (function () {that.scroll_lists.push (that.scroll_lists [0]); that.scroll_lists.shift (); that.animate=false;}, 1500)}) so far, the study on "how to achieve text scrolling in vuejs" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report