使用ElementUi中Carousel走马灯实现H5轮播图,可手动左右滑动图片

使用ElementUi中Carousel走马灯实现(H5)轮播图,可手动左右滑动图片

<template>
  <div class="bottom_layer">
    <div class="white_layer">
      <el-carousel ref="nop" arrow="never" height="180px" :autoplay="type">
        <div @touchstart="start($event)" @touchmove="move($event)">
          <el-carousel-item class="el_carousel__item_style" v-for="item in list">
            <el-image class="el_carousel__item_image" :src="item.value"></el-image>
          </el-carousel-item>
        </div>
      </el-carousel>
      <div style="width: 100%;float: left; ">
        <div style="width: 100%;text-align: center;margin-top: 16px;">
          <div class="a_div_label_top">
            <label>姓名:</label>
            <label>张三</label>
          </div>
          <div class="a_div_label_top">
            <label>票号:</label>
            <label>XD0011380HNU4B</label>
          </div>
        </div>
      </div>
      <hr style="border: 4px solid #EEEEEE"></hr>
      <div style="float: left;height: 300px;margin-top: 16px;">
        <div class="a_div_label">
          <label>购票信息:</label>
          <label>test</label>
        </div>
        <div class="a_div_label">
          <label>订单编号:</label>
          <label>XD0011380HNU4B</label>
        </div>
        <div class="a_div_label">
          <label>票类型:</label>
          <label>套票</label>
        </div>
        <div class="a_div_label">
          <label>有效期:</label>
          <label>2021-10-30</label>
        </div>
        <div class="a_div_label">
          <label>订单金额:</label>
          <label>99.99</label>
        </div>
        <div class="a_div_label">
          <label>游客姓名:</label>
          <label>张三</label>
        </div>
        <div class="a_div_label">
          <label>手机号码:</label>
          <label>18546532544</label>
        </div>
        <div class="a_div_label">
          <label>证件号码:</label>
          <label>500236199907176035</label>
        </div>
        <div class="a_div_label">
          <label>如有疑问请咨询:</label>
          <label>18580573666</label>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Template",
  data() {
    return {
      type: false,
      list: [{
        "name": 1,
        "value": "https://img9.51tietu.net/pic/2019-091322/ejrclz2dfpiejrclz2dfpi.jpg"
      }, {
        "name": 2,
        "value": "https://img9.51tietu.net/pic/2019-091322/mq1fqfjao1gmq1fqfjao1g.jpg"
      }, {
        "name": 3,
        "value": "https://img9.51tietu.net/pic/2019-091322/4xber0hs4r34xber0hs4r3.jpg"
      }, {
        "name": 4,
        "value": "https://img9.51tietu.net/pic/2019-091322/51hpcsvk4mc51hpcsvk4mc.jpg"
      }],
      startX: '',
      startY: '',
      moveY: '',
      moveX: '',
      startTime: '',
    }
  },
  methods: {



    start(e) {
      this.startX = e.touches[0].clientX;
      this.startY = e.touches[0].clientY;
    },
    move(e) {
      this.moveX = e.touches[0].clientX;
      this.moveY = e.touches[0].clientY;
      var nowtime = new Date().getTime();
      if (this.startTime == undefined || nowtime > this.startTime) {
        if (this.startX - this.moveX <= 0) { // 右滑触发
          this.prev();
          return false;
        } else {
          this.next();
          return false;
        }
      }
    },
    prev() {
      this.$refs.nop.prev();
      this.startTime = new Date().getTime() + 500;
    },
    next() {
      this.$refs.nop.next();
      this.startTime = new Date().getTime() + 500;
    },
  }
}
</script>

<style>

.white_layer {
  background-color: #fff;
  height: 100%;
  width: 96%;
  margin-left: 2%
}

.bottom_layer {
  background-color: #EEEEEE;
  height: 100%;
  width: 100%
}

.a_div_label_top {
  height: 28px;
  width: 100%;
  font-size: 12px;
}

.a_div_label {
  height: 28px;
  width: 96%;
  margin-left: 18px;
  font-size: 12px;
}

.div_lable_font {
  height: 100px;
  border: 1px solid #1e1e1e;
}

.el_carousel__item_image {
  width: 160px;
  height: 160px;
  margin-top: 20px;
}

.el_carousel__item_style {
  text-align: center;
  height: 180px;
}
</style>
View Code

图片效果如下:

 

 

posted @ 2021-10-20 16:31  初见如月  阅读(1996)  评论(0编辑  收藏  举报