vue从下往上滚动广告栏

两种实现方式:个人更倾向第二种

第一种:

//第一种实现方式:

<template>
  <div class="roll" v-show="cardBuyers && cardBuyers.length > 0">
    <div class="roll_cont">
      <div :class="{ marquee_top: animate }" class="roll_con">
        <div class="roll_box" v-for="(item, index) in cardBuyers" :key="index">
          <div class="roll_main">
            <img class="head_img" src="./image/header_bg.png" alt="" />
            <!-- <img v-show="item.headImg" class="head_img" :src="item.headImg" alt /> -->
            <div class="txtWrap">
              <p class="txt">{{ item.name }}买了{{ item.num }}万个会员</p>
            </div>
          </div>
          <p class="time">{{ item.time }}小时前</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: "AdvertRoll", //滚动广告栏
  // props: {
  //   cardBuyers: {
  //     type: Array,
  //     default: [],
  //   },
  // },
  data() {
    return {
      animate: false,
      setInTime: "", // 定时器
      cardBuyers: [
        {
          name: "张经理",
          num: 10000,
          time: 2,
        },
        {
          name: "李经理",
          num: 10000,
          time: 10,
        },
        {
          name: "王客户",
          num: 10000,
          time: 10,
        },
        {
          name: "胡经理",
          num: 10000,
          time: 10,
        },
      ],
    };
  },
  destroyed() {
    clearInterval(this.setInTime); // 页面销毁时清除定时器
  },
  mounted() {
    this.setInTime = setInterval(this.showMarquee, 3000);
  },
  methods: {
    // 滚动栏滚动
    showMarquee() {
      this.animate = true;
      setTimeout(() => {
        this.cardBuyers.push(this.cardBuyers[0]);
        this.cardBuyers.shift();
        this.animate = false;
      }, 500);
    },
  },
};
</script>

<style scoped>
.roll {
  width: 100%;
  height: 38px;
  overflow: hidden;
}
.txtWrap {
  display: inline;
  padding-top: 2px;
}
.roll_cont {
  margin-left: 10px;
  margin-right: 14px;
}
.roll_con {
  width: 100%;
  margin: 0 auto;
}
.roll_main {
  justify-content: center;
  align-items: center;
  vertical-align: middle;
  margin-top: 9px;
  margin-left: 10px;
}
.head_img {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 6px;
  border-radius: 50%;
  border: solid 0.5px #ffffff;
  text-align: center;
}
.marquee_top {
  width: 100%;
  transition: all 0.5s;
  /* 容器高度 */
  margin-top: -30px;
  overflow: hidden;
}
.roll_box {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: center;
  margin: 0 auto;
}
.txt {
  font-size: 12px;
  color: #fa5d1d;
  text-align: center;
  margin: 0;
  padding: 0;
  display: inline;
}
.time {
  font-size: 12px;
  color: #999999;
  text-align: center;
  margin: 0;
  padding: 0;
  margin-top: 6px;
}
</style>

方法二:

在RollAdvert.vue

<template>
  <div class="horn_con" v-if="tipsInfo">
    <van-notice-bar left-icon="volume-o" :scrollable="false" class="horn">
      <img src="../member/images/horn_icon.png" alt="" class="horn_icon" />
      <van-swipe
        vertical
        class="notice-swipe"
        :autoplay="1500"
        :show-indicators="false"
      >
        <van-swipe-item v-for="(item, index) in tipsInfo">{{
          item
        }}</van-swipe-item>
      </van-swipe>
    </van-notice-bar>
  </div>
</template>

<script>
import Vue from 'vue';
import { Tab, Tabs, NoticeBar, Swipe, SwipeItem } from 'vant';
import 'vant/lib/index.less';
Vue.use(NoticeBar).use(Swipe).use(SwipeItem);
export default {
  name: 'RollAdvert',
  components: { Tab, Tabs, NoticeBar, Swipe, SwipeItem },
  props: ['isMember', 'tipsInfo'],
  data () {
    return {
      isVip: false,
    }
  },
  watch: {
    isMember (newVal, oldVal) {
      this.isVip = newVal
    }
  },
  mounted () {
    document.body.style.backgroundColor = "#F6F7F8";
  },

}
</script>

<style lang="scss" scoped>
.horn {
  width: 85%;
  margin-left: 3.5%;
  margin-top: 12px;
  border-radius: 4px;
  margin-bottom: 12px;
}
.horn_icon {
  width: 20px;
  height: 20px;
  text-align: center;
  margin-left: 8px;
}
.horn_text {
  width: 100%;
  overflow: hidden;
  font-size: 13px;
  font-family: PingFang, PingFang-SC;
  font-weight: SC;
  text-align: left;
  color: #fa5d1d;
  margin-left: 6px;
}
::v-deep .van-tabs__content {
  // position: absolute;
  // top: 104px;
  // width: 100%;
  // background: #f6f7f8;
  // padding-bottom: 60px;
}
::v-deep .van-tabs__line {
  position: absolute;
  bottom: 15px;
  left: 0;
  z-index: 1;
  width: 40px;
  height: 3px;
  background: #1283ff;
  border-radius: 200px 0px 0px 200px;
}
.notice-swipe {
  height: 40px;
  line-height: 40px;
}
::v-deep .van-notice-bar {
  i {
    display: none;
  }
}
::v-deep .van-notice-bar__content {
  display: flex;
  align-items: center;
}
::v-deep .van-swipe-item {
  margin-left: 7px;
}
</style>

在Index.vue页面应用时候:

<template>
  <div>
    <RollAdvert :tipsInfo="tipsInfo" />
  </div>
</template>
<script>

import RollAdvert from "./RollAdvert";

export default {
  name: "Index",
  components: { RollAdvert },
  data () {
    return {
      tipsInfo: ['红红火火恍恍惚惚或或或或或或或'],
    };
  },

}
</script>
<style scoped lang='scss'>
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值