vue 列表内容自动向上滚动_【功能记录】Vue列表向上滚动无缝连接

本文介绍了如何在Vue中实现列表内容自动向上滚动并做到无缝连接。通过设置定时器调整容器的translateY值,当一个容器滚动到指定位置时,另一个容器开始衔接滚动,从而达到平滑过渡的效果。
摘要由CSDN通过智能技术生成

最近给朋友帮忙的时候遇到一个列表向上滚动无缝连接功能的需求,整理了下思路,把这个功能草草的做出来了,尚未做优化完善,先记录一下吧~

Html代码

  • {{item.accountName}}
  • {{item.accountName}}

Data数据

x: 0, //list1容器的translateY值

y: 0, //list2容器的translateY值

winnerList: [ //滚动数据

{

accountName: "1",

id: "0",

profit: "58354",

}

.......

]

js逻辑

mounted: function () {

this.scroll(); //执行滚动函数

},

watch: {},

methods: {

scroll() {

let ofHeight = this.$refs.edic.offsetHeight; //获取容器offsetHeight

let interVal = setInterval(() => { //设定定时器

this.x -= 2; //每次执行-2

console.log(this.x); //容器1上滚

if (this.x <= -ofHeight) { //当上滚像素大于等于容器offsetHeight

clearInterval(interVal); //停止定时器

interVal = setInterval(() => { //重新定义定时器

this.x -= 2; //容器1继续上滚

console.log(this.x);

this.y -= 2; //容器2衔接上滚

if (this.x <= -(2 * ofHeight)) { //当容器1上滚像素为2倍的offsetHeight时

this.x = 0; //translateY的值设定回0

}

if (this.y <= -(2 * ofHeight)) { //当容器2上滚像素为2倍的offsetHeight时

this.y = 0; //translateY的值设定回0

}

}, 50); //50毫秒执行一次

}

}, 50); //50毫秒执行一次

},

},

};

CSS样式

* {

margin: 0;

padding: 0;

}

ul,

li {

list-style: none;

box-sizing: border-box;

}

.light {

position: fixed;

right: 200px;

top: 200px;

width: 200px;

height: 600px;

border: 1px solid #ccc;

box-sizing: border-box;

overflow: hidden;

ul {

width: 100%;

height: 100%;

box-sizing: border-box;

li {

height: 40px;

width: 100%;

border-bottom: 1px solid #ccc;

display: flex;

justify-content: center;

align-items: center;

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值