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 achieve simple and seamless scrolling effect with vue

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the knowledge of "how to achieve simple and seamless scrolling effect in vue". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Effect.

Realization idea

How to copy a list in vue without losing bound events? simply use slot slots, using two slots, we have two lists.

Component complete code

Export default {name: "listScroll", created () {}, mounted () {/ / do not scroll if (this.boxHeight) when the box content height is less than the visible height

< this.ele0.clientHeight) { this.start(this.height); this.setEvet(); } else { this.isScroll = false; } }, props: { speed: { default: 1, type: Number, }, }, computed: { //第一个slot ele0() { return this.$refs.box.children[0]; }, //第二个slot ele1() { return this.$refs.box.children[1]; }, //盒子的可视高度 boxHeight() { return this.$refs.box.clientHeight; }, }, data() { return { height: 0, isScroll: true, }; }, methods: { //鼠标移入停止滚动 移出继续滚动 setEvet() { this.$refs.box.onmouseenter = () =>

{this.isScroll = false; / / this.height = 0;}; this.$refs.box.onmouseleave = () = > {this.isScroll = true; this.$nextTick (() = > {this.start (this.height);});}, / / scrolling method start (height) {this.ele0.style = `transform:translateY (- ${height} px) `; this.ele1.style = `height:$ {this.boxHeight} px;transform:translateY (- ${height} px); overflow: hidden;`; if (height > = this.ele0.clientHeight) {this.height = 0;} else {this.height + = this.speed;} if (! this.isScroll) return; window.requestAnimationFrame (() = > {this.start (this.height);}) },},}; .listScroll {overflow: hidden;}. Hover {overflow-y: auto;}. Hide {display: none;}

Use

{{item.xh}} {{item.label}} import ListScroll from "@ / components/listScroll"; export default {name: "scroll", components: {ListScroll}, data () {return {list: new Array (10) .fill (1) .map ((s, I) = > ({xh: I + 1, label: "hello wrold"}),};},} .box {height: 300px;} .list {padding: 010px; width: 300px; .item {display: flex; justify-content: space-between; padding: 5px 0; cursor: pointer; &: hover {background-color: # 95a5a6;} "how vue achieves simple seamless scrolling" ends here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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