el-carousel 自定义 指示灯

67 篇文章 7 订阅

在element中提供的 只能是在指定位置上设置 所以通过属性无法设置其他 位置 所以我们只能去手动添加位置  

效果图

 

<template>
  <div class="container-swiper">
    <div
      class="smallMask2"
      v-if="$store.state.search.isShowSearchHistory"
    ></div>
    <div
      class="smallMask"
      @click.stop="closeSearch"
      v-if="$store.state.search.isShowSearch"
    ></div>
    <div class="container-swiper-title">
      <div>
        <img src="../../assets/HomePage/swiper-title.png" alt="" />
        <p>最新公告</p>
      </div>
      <div class="swiperToggle">
        <ul class="circle">
          <!-- v-for  -->
          <li
            :class="{ curLightHeight: lightHeight == idx }"
            v-for="(item, idx) in 5"
            :key="item"
            @click="toggleSwiper(idx)"
          ></li>
        </ul>
        <div class="arrowToggle">
          <div class="prev" @click="prev"></div>
          <div class="next" @click="next"></div>
        </div>
      </div>
    </div>
    <!-- arrow="never" 隐藏左右箭头 -->
    <el-carousel
      trigger="click"
      :interval="3000"
      class="swiper-box"
      arrow="never"
      ref="carousel"
      @change="change"
    >
      <el-carousel-item
        class="swiper-content-box"
        v-for="(item,index) in noticeList"
        :key="item.id"
      >
        <div class="smallSwiper">
          <div>
            <p class="order"> {{index}} </p>
            <p class="timer"> {{item.create_time_text}} </p>
          </div>
          <div>
            <p class="title"> {{item.title}} </p>
            <p class="secondTitle"> {{item.des}} </p>
          </div>
        </div>
         <div class="smallSwiper">
          <div>
            <p class="order"> {{index}} </p>
            <p class="timer"> {{item.create_time_text}} </p>
          </div>
          <div>
            <p class="title"> {{item.title}} </p>
            <p class="secondTitle"> {{item.des}} </p>
          </div>
        </div>
        <!-- <div>
          <div class="smallSwiper">
            <p class="order">02</p>
            <p class="timer">2020/11-24</p>
          </div>
          <div>
            <p class="title">国家煤监局赴山西吕梁市明察暗访发现有法律综合</p>
            <p class="secondTitle">按照应急管理部、国家煤监局安排</p>
          </div>
        </div> -->
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script>
import { getNotice } from '@/api/index'
export default {
  created () {
    this.getNotice();
  },
  data() {
    return {
      lightHeight: 0,
      noticeList:[]
    };
  },
  methods: {
    closeSearch() {
      this.$store.commit("search/editShowSearch", false);
      this.lightHeight = this.$refs.carousel.activeIndex;
    },
    prev() {
      this.lightHeight = this.$refs.carousel.activeIndex;
      this.$refs.carousel.prev();
    },
    next() {
      this.lightHeight = this.$refs.carousel.activeIndex;
      this.$refs.carousel.next();
    },
    toggleSwiper(idx) {
      this.$refs.carousel.setActiveItem(idx);
      this.lightHeight === idx;
    },
    change() {
      this.lightHeight = this.$refs.carousel.activeIndex;
    },
    async getNotice(){
      try {
        const res = await getNotice()
        console.log('getNotice', res.data.list)
        this.noticeList=res.data.list
        // 保存数据
      } catch (err) {
        console.log('getNotice', err)
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.container-swiper {
  position: relative;
  width: 12rem;
  height: 1.78rem;
  margin: 0.82rem auto 0;
  padding: 0.33rem;
  background-color: #fff;
}

.container-swiper-title {
  position: relative;
  display: flex;
  margin-bottom: 0.18rem;
  p {
    font-size: 0.24rem;
  }
  .swiperToggle {
    position: absolute;
    right: 0;
    font-size: 0.2rem;
    // 小轮播 源点

    .circle {
      display: flex;
      width: 0.72rem;
      margin-right: 0.28rem;
      justify-content: space-around;
      li {
        width: 0.08rem;
        height: 0.08rem;
        cursor: pointer;
        border-radius: 50%;
        background: #257cff;
        opacity: 0.2;
      }
      .curLightHeight {
        background: #257cff;
        opacity: 1;
      }
    }
    .arrowToggle {
      display: flex;
      .prev,
      .next {
        cursor: pointer;
        width: 0.2rem;
        height: 0.2rem;
      }
      .prev {
        margin-right: 0.12rem;
        background-image: url("../../assets/HomePage/zuo 2@2x.png");
        background-size: cover;
      }
      .next {
        background-image: url("../../assets/HomePage/zuo 1@2x.png");
        background-size: cover;
      }
    }
  }
}

.container-swiper-title > div:nth-child(1) {
  display: flex;
  align-items: center;
  & > img {
    width: 0.22rem;
    height: 0.21rem;
    margin-right: 0.08rem;
  }

  & > p {
    font-size: 0.24rem;
    font-weight: 700;
    color: #257cff;
  }
}

.container-swiper-title > div:nth-child(2) {
  display: flex;
  align-items: center;
  & > img {
    width: 0.22rem;
    height: 0.21rem;
    margin-right: 0.08rem;
  }

  & > p {
    font-size: 0.24rem;
    color: #257cff;
  }
}

.swiper-content-box {
  display: flex;
  height: 1.78rem;
  justify-content: space-between;
  color: #323233;
  .order {
    text-align: center;
    font-size: 0.28rem;
  }
  .timer {
    font-size: 0.14rem;
    color: #646566;
  }
  .title {
    font-size: 0.18rem;
    margin-bottom: 0.15rem;
  }
  .secondTitle {
    font-size: 0.14rem;
    color: #646566;
  }
}
.swiper-content-box > div[data-v-1d3e6b1c] {
  height: 1rem;
}
.swiper-content-box > div {
  display: flex;
  width: 47%;
  & > div:first-child {
    padding-right: 0.22rem;
  }
}

.el-carousel--horizontal {
  height: 1rem;
}
::v-deep .el-carousel__container {
  height: 1rem;
  overflow: hidden;
}

.smallMask {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 99;
}
.smallMask2 {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 999999999999;
}
</style>

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值