vue电商开发记录2—实现公告轮播组件

16 篇文章 4 订阅

关注我的个人博客:https://pinbolei.cn,获取更多内容

简单说一下用vue实现一个电商公告轮播组件

电商平台中常会有公告轮播图,虽然我浏览电商网站的时候,常常会忽略掉它~~~,
emmmmm…,切回正题,今天分享一个电商公告轮播的小栗子,仅供参考

公告轮播

html部分

<template>
  <div class="swiper">
    <!-- 左边公告,放个图片什么的 -->
    <div class="swiper_title">
      <span>公告:</span>
    </div>
    <!-- 右边为公告内容 -->
    <div class="swiper_box">
      <ul class="swiper_list" :class="{swiper_top:animate}">
        <li v-for="(item,index) in swiperList" :key="index">{{item.text}}</li>
      </ul>
    </div>
  </div>
</template>

js部分

<script>
export default {
  data () {
    return {
      animate: false,
      swiperList: [
        {
          text: '苹果促销大甩卖啦!'
        },
        {
          text: '香蕉促销大甩卖啦!!'
        },
        {
          text: '草莓促销大甩卖啦!!'
        }
      ]
    };
  },
  created () {
    // 页面显示
    setInterval(this.showSwiper, 3000);
  },
  methods: {
    showSwiper () {
      this.animate = true;
      setTimeout(() => {
        this.swiperList.push(this.swiperList[0]);
        this.swiperList.shift();
        this.animate = false;
      }, 1000);
    }
  }
};
</script>

css部分

<style lang="scss" scoped>
.swiper {
  margin-top: 10px;
  width: 100%;
  align-items: center;
  color: #3a3a3a;
  background-color: white;
  display: flex;
  box-sizing: border-box;
  overflow: hidden;
  font-size: 14px;
  font-weight: bold;
}
.swiper_title {
  height: 30px;
  padding-left: 29px;
  background: url(static/images/swiper.gif) 2px 3px no-repeat;
  span {
    font-size: 14px;
    color: #ca010b;
  }
}
.swiper_box {
  display: block;
  position: relative;
  width: 60%;
  height: 37px;
  overflow: hidden;
}
.swiper_list {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
}
.swiper_top {
  transition: all 0.5s;
  margin-top: -30px;
}
.swiper_list li {
  height: 30px;
  line-height: 30px;
  font-size: 14px;
  color: #ca010b;
}
.swiper_list li span {
  padding: 0 2px;
}
</style>

效果

效果图

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值