dom部分pug模板
ul.list.ulScroll(:style="{ top }")
li.item {{item}}
private activeIndex:number=0;
get top():string {
return - this.activeIndex * 35 + 'px';
}
private mounted(): void {
let _this = this;
setInterval(function(){
if(_this.activeIndex < _this.list.length-5) {
_this.activeIndex +=1;
} else {
_this.activeIndex = 0;
}
}, 1000);
}
<style lang="styles">
.rankingScroll
height 175px
overflow hidden
position relative
.ulScroll
margin 0;
position relative
transition top 0.5s
-webkit-transition top 0.5s
.item
display flex
align-items center
height 35px
line-height:35px
</style>
轮播?
单向轮播的话,复制第一个到最后一个.
比如
[1],2,3
将第一个复制到最后,变成:[1],2,3,1
滚动到索引为3时,将索引切换为0.双向轮播同样,将最后一个复制到最前面,变成:
3,[1],2,3,1
项目里找了个组件.
使用方式
附一个在线DEMO