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 vertical seamless scrolling of list by vue

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

Share

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

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

Realize the rotation of the news list (as shown in the following figure)

Upper code

Encapsulated so-marquee.vue

Import {parseToNum, generateId} from'@ / utils/util'export default {name: "so-marquee", props: {/ * * acceptable parameters * data list data * className Custom Class name * width list width Default: 400 * height list height, default: 200 * number of showNumber visible entries, default: 5 * speed rotation speed Default value: 1000 * * / / list data data: {type: Array, default: () = > [],}, / / Custom class name className: String, / / list width Default value: 400 width: {type: [Number, String], default: 400}, / / list height, default value: 200 height: {type: [Number, String], default: 200}, / / number of visible entries Default value: 5 showNumber: {type: [Number, String], default: 5}, / / rotation speed Default value: 1000 speed: {type: [Number, String], default: 1000}}, data () {return {intnum: undefined, animate: false} }, computed: {tooltipId () {return `marquee-con-$ {generateId ()} ` }, realWidth () {return parseToNum (this.width)}, realHeight () {return parseToNum (this.height)}, realShowNumber () {return parseToNum (this.showNumber)}, realSpeed () {return parseToNum (this.speed)

< 1000 ? 1000 : parseToNum(this.speed) }, itemHeigth() { return this.realHeight / this.realShowNumber }, realData() { return JSON.parse(JSON.stringify(this.data)) } }, mounted() { if (this.realData.length >

This.realShowNumber) {this.scrollUp ();}}, methods: {scrollUp () {/ / eslint-disable-next-line no-unused-vars this.intnum = setInterval (_ = > {this.animate = true; setTimeout (()) > {this.realData.push (this.realData [0])) / / add the first element of the array to the this.realData.shift () of the array; / / delete the first element of the array this.animate = false / / cancel the transition animation when margin-top is 0 to achieve seamless scrolling}, this.realSpeed / 2) this.$once ('hook:beforeDestroy', () = > {this.cleanup ()})}, this.realSpeed) }, handleStop () {this.cleanup ()}, handleUp () {this.scrollUp ();}, handleClick (row) {this.$emit ('handleClick', row)}, cleanup () {if (this.intnum) {clearInterval (this.intnum) This.intnum = null;}}, beforeDestroy () {this.cleanup ();}, deactivated () {this.cleanup () }, watch: {animate (flag) {this.marqueeCon = this.$refs.marqueeCon if (flag) {this.marqueeCon.style.marginTop = `- ${this.itemHeigth} px`} else {this.marqueeCon.style.marginTop = 0}},}}; .marquee-container {overflow: hidden } .marquee-content {position: relative;} .anim {transition: all 0.5s;} .marquee-item {display: flex; align-items: center; justify-content: space-around;}

ParseToNum method

Export function parseToNum (value) {if (value! = = undefined) {value = parseInt (value, 10) if (isNaN (value)) {value = null;}} return value}

GenerateId method

Export const generateId = function () {return Math.floor (Math.random () * 10000);}

Parent component invocation

{{item.id}} {{item.name}} {{item.date}} import soMarquee from'. / components/so-marquee'export default {name: 'App', data () {return {jsonData: [{id: 1 Name: "meeting Notification", date: "2020-02-01"}, {id: 2, name: "Holiday Notification", date: "2020-02-02"} {id: 3, name: "Water outage notice", date: "2020-02-03"}, {id: 4, name: "Power outage Notification" Date: "2020-02-04"}, {id: 5, name: "parking notice", date: "2020-02-05"}, {id: 6 Name: "reward notice", date: "2020-02-06"}, {id: 7, name: "punishment notice", date: "2020-02-07"} {id: 8, name: "Disciplinary 8 Notification", date: "2020-02-08"}, {id: 9, name: "Disciplinary 9 Notification" Date: "2020-02-09"}, {id: 10, name: "punishment 10 notice", date: "2020-02-10"},]}} Components: {soMarquee}, methods: {handleMarqueeClick (row) {alert (`The currently clicked ${row.id} line `)}} .my-ui-marquee {:: v-deep.marquee-item {cursor: pointer }} at this point, the study on "how to achieve vertical seamless scrolling of the list by vue" is over. I hope to be able to solve your 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