vue-无缝滚动

<template>
  <div id="box">
    <ul id="con1" ref="con1" :class="{anim:animate==true}">
      <li v-for='item in items'>{{item.name + item.name}}</li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  data () {
    return {
      animate:false,
      items:[  //消息列表对应的数组
        {name:"马云"},
        {name:"雷军"},
        {name:"王勤"},
        {name:"马云1"},
        {name:"雷军1"},
        {name:"王勤1"},
        {name:"马云2"},
        {name:"雷军2"},
        {name:"王勤2"},
      ],
      page: [1, 2, 3, 4, 5]
    }
  },
  created(){
    setInterval(this.scroll,2500)
  },
  methods: {
    scroll(){
      this.animate = true
      setTimeout(() => {
        this.items.push(this.items[0]);
        this.items.shift();
        this.animate= false;  // 这个地方如果不把animate 取反会出现消息回滚的现象,此时把ul 元素的过渡属性取消掉就可以完美实现无缝滚动的效果了
      },1500)
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  *{
    margin: 0 ;
    padding: 0;
  }
  #box{
    width: 300px;
    height: 62px;
    line-height: 30px;
    overflow: hidden;
    padding-left: 30px;
    border: 1px solid black;
    transition: all 0.5s;
  }
  .anim{
    transition: all 1.5s;
    margin-top: -34px;
  }
  #con1 li{
    list-style: none;
    line-height: 34px;
    height: 34px;
  }
</style>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值