zoukankan      html  css  js  c++  java
  • vue消息无缝滚动

    HTML:

    <div class="marquee">

      <ul class="nameList" :class="{anim:animate==true}">
        <li v-for='(item,index) in marqueeList' :key="index">{{item.name}}</li>

      </ul>
    </div>

    script:

    export default {
      data() {
        return {
          animate: false,
          marqueeList: [ 

            {name: "抖音"},

            {name: "虎牙"},

            {name: "淘宝"},

            {name: "京东"},
            {name: "微博"},

            {name: "微信"}
          ]

        };

      },

      created() {
        if (this.marqueeList.length > 2) {
          setInterval(this.showMarquee, 2000);
        }
      }, 

      methods: {
        showMarquee() {
          this.animate = true;
          setTimeout(() => {
            this.marqueeList.push(this.marqueeList[0]);
            this.marqueeList.shift();
            this.animate = false;// 这个地方如果不把animate 取反会出现消息回滚的现象,此时把ul 元素的过渡属性取消掉就可以完美实现无缝滚动的效果了

          }, 1000);
        },

      }

    }

    style:

    .marquee
       300px;
      height: 60px;
      line-height: 30px;
      overflow: hidden;
      padding-left: 30px;
      border: 1px solid black;
      transition: all .5s;
    .anim
      transition: all 1s;
      margin-top: -30px;
    .nameList li
      list-style: none;
      line-height: 30px;
      height: 30px;

  • 相关阅读:
    Centos 6.5 在 Dell 服务器安装的记录
    【转载】你真的了解补码吗
    【转载】我对补码的理解
    记录一下家里双路由实现wifi漫游功能
    中国大学MOOC | C语言程序设计入门 第8周编程练习 翁恺
    华为卡刷包线刷方法
    串口通信
    端口复用和端口重映射
    软件仿真和硬件仿真
    FPGA之四位LED灯
  • 原文地址:https://www.cnblogs.com/CMing/p/9817228.html
Copyright © 2011-2022 走看看