In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces Vue how to achieve racing lantern style text horizontal scrolling, the article is very detailed, has a certain reference value, interested friends must read it!
Demand:
At the top of the Vue project, scroll the text left and right
Steps:
1. You can encapsulate a component yourself, write it yourself, or copy the following code
2. After the encapsulation is completed, it is necessary to introduce, register, and use the required components
Code:
Encapsulate a component specially used to achieve the effect of horse racing lantern marquee component
{{text}}
{{text}}
Export default {name: 'marquee', props: [' val'], data () {return {timer: null, text:''}}, created () {let timer = setTimeout (() = > {this.move () clearTimeout (timer)}, 1000)}, mounted () {for (let item of this.val) {this.text + = item}} Methods: {move () {let maxWidth = this.$refs ['marquee-wrap']. ClientWidth let width = this.$refs [' getWidth']. ScrollWidth if (width {distance-= 1 if (- distance > = width) {distance = 16} scroll.style.transform = 'translateX (' + distance +'px)'}, 20)}} BeforeDestroy () {clearInterval (this.timer)}. Marquee-wrap {width: 100% Overflow: hidden; position: relative;} .marquee {margin-right: 0.16remt;} p {word-break:keep-all; white-space:nowrap; font-size: 0.28remr;} .getWidth {word-break:keep-all; white-space:nowrap; position: absolute; opacity: 0; top: 0;}
In which component is used, introduce
/ / introduce the racing lantern component import marquee from "@ / components/marquee/marquee.vue"
Reference and register
Export default {components: {/ / register racing lantern assembly marquee,},}
After registration, the next step is the Html style, which is used in the template template
{{item.city}}
Then there is the effect picture:
In order to get a more obvious effect, I took a few more pictures.
The above is all the contents of this article "how to achieve horizontal scrolling of text in the style of horse racing lanterns in Vue". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.