滚动数据展示

23 篇文章 0 订阅
17 篇文章 0 订阅

<template>
  <div id="box">
    <div
      id="con1"
      ref="con1"
      :class="{ anim: animate == true }"
      @mouseenter="mEnter"
      @mouseleave="mLeave"
    >
      <!-- <p v-for="item in items" :key="item.name">中奖人的名字是--{{ item.name }}</p> -->
      <div v-if="from === 'und'">
        <div
          v-for="(item, index) in items"
          :key="index"
          class="data-item"
          :class="item.active % 2 === 0 ? 'bg-item' : ''"
        >
          <div>{{ item.name }}</div>
          <div>{{ item.detail }}</div>
          <div>{{ item.date }}</div>
        </div>
      </div>
      <div v-else-if="from === 'build'">
        <div
          v-for="(item, index) in items"
          :key="index"
          class="data-item"
          :class="item.active % 2 === 0 ? 'bg-item' : ''"
        >
          <div>{{ item.time }}</div>
          <div>{{ item.id }}</div>
          <div>{{ item.from }}</div>
          <div>{{ item.type }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script> 
export default {
  props: {
    from: {
      type: String,
    },
  },
  data() {
    return {
      animate: false,
      undergroundDataList: [
        //消息列表对应的数组
        { name: "燃气", detail: "其他", date: "2021-9-21" },
        { name: "供水", detail: "流量异常", date: "2021-9-23" },
        { name: "电力", detail: "其他", date: "2021-9-25" },
        { name: "水管", detail: "压力异常", date: "2021-9-30" },
        { name: "燃气", detail: "其他", date: "2021-9-21" },
        { name: "供水", detail: "流量异常", date: "2021-9-23" },
        { name: "电力", detail: "其他", date: "2021-9-25" },
        { name: "水管", detail: "压力异常", date: "2021-9-30" },
      ],
      crossDoorPeopleList: [
        { time: "9:25", id: "工号003", from: "从东南门", type: "进入" },
        { time: "9:35", id: "工号025", from: "从东门", type: "进入" },
        { time: "9:38", id: "工号012", from: "从南门", type: "外出" },
        { time: "9:48", id: "工号054", from: "从西南门", type: "进入" },
        { time: "9:55", id: "工号083", from: "从东南门", type: "外出" },
        { time: "9:58", id: "工号078", from: "从北门", type: "外出" },
      ],
    };
  },
  created() {
    if (this.from === "und") {
      this.items = this.undergroundDataList;
    } else if ((this.from = "build")) {
      this.items = this.crossDoorPeopleList;
    }
    this.items.forEach((item, index) => {
      if (index % 2 === 0) {
        item.active = true;
      } else {
        item.active = false;
      }
    });
  },
  mounted() {
    this.timer1 = setInterval(this.scroll, 1000);
  },
  beforeDestroy() {
    clearInterval(this.timer1);
  },
  methods: {
    scroll() {
      let con1 = this.$refs.con1;
      con1.style.marginTop = "-35px";
      this.animate = !this.animate;
      var that = this; // 在异步函数中会出现this的偏移问题,此处一定要先保存好this的指向
      setTimeout(function () {
        that.items.push(that.items[0]);
        that.items.shift();
        con1.style.marginTop = "0px";
        that.animate = !that.animate; // 这个地方如果不把animate 取反会出现消息回滚的现象,此时把ul 元素的过渡属性取消掉就可以完美实现无缝滚动的效果了
      }, 500);
    },
    mEnter() {
      clearInterval(this.timer1);
    },
    mLeave() {
      this.timer1 = setInterval(this.scroll, 1000);
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
* {
  margin: 0;
  padding: 0;
}
#box {
  width: 100%;
  /* height: 320px; */
  line-height: 35px;
  overflow: hidden;
  transition: all 0.5s;
  /* background-color: pink; */
}
.anim {
  transition: all 0.5s;
}
#con1 li {
  list-style: none;
  line-height: 35px;
  height: 35px;
}

.data-item {
  display: flex;
  justify-content: space-between;
  /* color: rgba(255, 255, 255, 0.6); */
  color: #fff;
  // padding: 0 21px;
  >div{
    display: flex;
    justify-content: center;
    flex: 1;
  }
}
.bg-item {
  background-color: rgba(0, 131, 192, 0.26);
  /* opacity: 0.26; */
}
</style>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq614756883

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值