element Carousel 走马灯 一次轮播3张图片(整理)

简介: element Carousel 走马灯 一次轮播3张图片(整理)

效果图:

<template>
  <div class="carouselBox">
    <el-carousel :loop="false" :autoplay="false" class="carousel">
      <el-carousel-item class="el-car-item" v-for="(list, index) in dataList" :key="index">
        <div v-for="(imgList,index1) in list" :key="index1" class="divSrc">
          <img class="img" :src="imgList.img" />
          <div class="title">{{imgList.title}}</div>
        </div>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>
<script>
  data() {
    return{
      dataList: [],
    },
    mounted(){
      this.byEvents();
    },
    methods: {
      byEvents() {
        this.dataList = [{
            img: 'https://picsum.photos/1250/650',
            title: '标题'
          },
          {
            img: 'https://picsum.photos/1250/650',
            title: '标题'
          },
          {
            img: 'https://picsum.photos/1250/650',
            title: '标题'
          },
          {
            img: 'https://picsum.photos/1250/650',
            title: '标题'
          },
          {
            img: 'https://picsum.photos/1250/650',
            title: '标题'
          },
          {
            img: 'https://picsum.photos/1250/650',
            title: '标题'
          },
          {
            img: 'https://picsum.photos/1250/650',
            title: '标题'
          },
          {
            img: 'https://picsum.photos/1250/650',
            title: '标题'
          },
          {
            img: 'https://picsum.photos/1250/650',
            title: '标题'
          },
          {
            img: 'https://picsum.photos/1250/650',
            title: '标题'
          },
          {
            img: 'https://picsum.photos/1250/650',
            title: '标题'
          },
          {
            img: 'https://picsum.photos/1250/650',
            title: '标题'
          },
          {
            img: 'https://picsum.photos/1250/650',
            title: '标题'
          },
        ]
        let newDataList = [];
        let current = 0
        if (this.dataList && this.dataList.length > 0) {
          for (let i = 0; i <= this.dataList.length - 1; i++) {
            if (i % 3 !== 0 || i === 0) { //数据处理成几张展示
              if (!newDataList[current]) {
                newDataList.push([this.dataList[i]])
              } else {
                newDataList[current].push(this.dataList[i])
              }
            } else {
              current++
              newDataList.push([this.dataList[i]])
            }
          }
        }
        this.dataList = [...newDataList]
      },
    }
  }
</script>
<style lang="scss" scoped>
  .carouselBox {
    margin: 0 auto;
    width: 1300px;
    height: 420px;
    background-color: #2276F5;
    .carousel{
      width: 100%;
      height: 420px;
      .el-car-item {
        width: 100%;
        height: 420px;
        display: flex;
        .divSrc{
          width: 403px;
          height: 420px;
          background: #fff;
          margin-right: 46px;
          .img {
            width: 403px;
            height: 335px;
          }
          .title{
            width: 90%;
            height: 80px;
            line-height: 80px;
            margin: 0 auto;
            text-align: center;
            font-size: 20px;
            font-weight: bold;
            color: #222222;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
        }
      }
      /deep/.el-carousel__arrow{
        background: red !important;
        display: block !important;
        margin-top: 65px;
      }
    }
    .el-car-item {
      width: 100%;
      display: flex;
      .img {
        width: 284px;
        height: 184px;
        margin-right: 20px;
        cursor: pointer;
      }
    }
  }
</style>
相关文章
|
5月前
|
前端开发 JavaScript
无缝滚动图片——源码
无缝滚动图片——源码
解决element-ui上传多张图片时闪动问题
解决element-ui上传多张图片时闪动问题
297 0
|
5月前
|
JavaScript
jquery给轮播图的第一张设置class样式
jquery给轮播图的第一张设置class样式
|
5月前
el-carousel和el-image组合实现swiper左右滑动图片,点击某张图片放大预览的效果
el-carousel和el-image组合实现swiper左右滑动图片,点击某张图片放大预览的效果
|
11月前
|
前端开发
前端切图|点击按钮div变色
前端切图|点击按钮div变色
42 0
|
前端开发
css鼠标滑过文字的波纹demo效果示例(整理)
css鼠标滑过文字的波纹demo效果示例(整理)
|
小程序 JavaScript
微信小程序rich-text富文本 解决图片超出屏幕宽度
微信小程序rich-text富文本 解决图片超出屏幕宽度
|
前端开发 JavaScript
一颗红心,三手准备,分别基于图片(img)/SCSS(样式)/SVG动画实现动态拉轰的点赞按钮特效
华丽炫酷的动画特效总能够让人心旷神怡,不能自已。艳羡之余,如果还能够探究其华丽外表下的实现逻辑,那就是百尺竿头,更上一步了。本次我们使用图片、SCSS样式以及SVG图片动画来实现“点赞”按钮的动画特效,并比较不同之处。
一颗红心,三手准备,分别基于图片(img)/SCSS(样式)/SVG动画实现动态拉轰的点赞按钮特效
|
前端开发
css:hover仿淘宝首页分类列表效果
css:hover仿淘宝首页分类列表效果
css:hover仿淘宝首页分类列表效果