向上滑动公告实现

(这是笔者工作的笔记)

简单的滑动轮播的实现,主要是限制可视区域overflow: hidden,然后用transition做一个向上平移一个li行高的0.5的动画,同时设置一个0.5秒的定时器改变data里数组的数据。在定时器里开关动画使得两者步骤同步,两者结合完成一个简单的向上滑动的轮播。
复制粘贴 vue serve xxx 即用

<template>
  <div class="marquee">
    <div class="marquee_box">
      <ul class="marquee_list" :class="{marquee_top:animate}">
        <li v-for="(item,index) in announcement" :key="indexjin">{{item}}</li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      announcement: [
        "测试公告:恭喜,璎珞本周的业绩取得第一名,特此公告。",
        "测试公告:恭喜,任颖本周的业绩取得第二名,特此公告。",
        "测试公告:恭喜,xxx本周的业绩取得第三名,特此公告。"
      ],
      animate:false
    };
  },
  methods: {
    showMarquee: function() {
      this.animate = true
      setTimeout(() => {
        this.announcement.push(this.announcement[0]);
        this.announcement.shift();
        this.animate = false;
      }, 500);
    }
  },
  created() {
    setInterval(this.showMarquee, 2000)
    //接受公告
    //  this.socketApi.sendSock("", res => {
    //   window.console.log(res)
    //   this.announcement = res.split(";");
    // });
  }
};
</script>

<style>
.marquee {
  width: 400px;
  height: 30px;
  align-items: center;
  color: #3a3a3a;
  background-color: white;
  display: flex;
  box-sizing: border-box;
  margin: 10px;
  overflow: hidden;
}
.marquee_box {
  margin: 10px;
  width: 100%;
  height: 30px;
  position: relative;
}
.marquee_list {
  position: absolute;
  margin: 0;
}
li {
  line-height: 30px;
  height: 30px;
/* list-style: none;
  list-style-image: url("./horn.png");  /*设置li图标*/ */  
}
.marquee_top {
  transition: all 0.5s;
  margin-top: -30px;
}
</style>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容