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>
相关文章
element中使用走马灯效果el-carousel点击按钮切换第几页demo效果示例(整理)
element中使用走马灯效果el-carousel点击按钮切换第几页demo效果示例(整理)
element el-cascader动态编辑赋值后,不回显的解决方法(整理)
element el-cascader动态编辑赋值后,不回显的解决方法(整理)
uniapp发送formdata表单请求(全网最简单方法)
因为uniapp不支持直接传输formdata,只提供了uploadFile方法上传文件,但是利用该方法就可以传输formdata了。
3752 1
vue3 element-ui-plus Carousel 跑马灯 的使用 及 踩坑记录
本文介绍了在Vue 3中使用Element UI Plus的Carousel组件实现跑马灯效果的方法,并分享了在实现过程中遇到的常见问题和解决方案。
vue3 element-ui-plus Carousel 跑马灯 的使用 及 踩坑记录
|
移动开发 资源调度 JavaScript
Vue2使用触摸滑动插件(Swiper)
这篇文章介绍了在Vue 3框架中如何使用Swiper插件来创建不同类型的触摸滑动组件,包括轮播图、淡入淡出效果和走马灯效果,并提供了详细的配置选项和使用示例。
1468 1
Vue2使用触摸滑动插件(Swiper)
|
12月前
|
JavaScript API 容器
Vue 3 中的 nextTick 使用详解与实战案例
Vue 3 中的 nextTick 使用详解与实战案例 在 Vue 3 的日常开发中,我们经常需要在数据变化后等待 DOM 更新完成再执行某些操作。此时,nextTick 就成了一个不可或缺的工具。本文将介绍 nextTick 的基本用法,并通过三个实战案例,展示它在表单验证、弹窗动画、自动聚焦等场景中的实际应用。
1139 17
|
JavaScript API
Vue2 中使用Swiper构建中间大两边小轮播效果
【10月更文挑战第8天】
2138 122
|
资源调度 JavaScript 前端开发
在 Vue 3 中实现流畅的 Swiper 滑动效果
本文介绍了如何在 Vue 3 项目中集成 Swiper,涵盖了从安装、基本用法到丰富的配置选项。通过简单的示例,读者将学习如何创建响应式的图片轮播,利用 Swiper 的循环、自动播放和自定义分页功能,提升用户体验。无论是简单的幻灯片还是复杂的滑块效果,Swiper 都能轻松实现,帮助开发者快速构建出美观的滑动组件。
3220 0
Vue2走马灯(Carousel)
这是一个基于 Vue2 的走马灯轮播组件(Carousel),支持鼠标移入暂停、移出后自动轮播。用户可以自定义设置轮播图片数组、滑动间隔时间、图片宽高。该组件提供了两种滑动效果实现方式:一种是通过 `setInterval` 延时调用,另一种是使用 `requestAnimationFrame()`,后者效果更佳。组件还支持图片懒加载,适用于多种应用场景。
834 0
Vue2走马灯(Carousel)

热门文章

最新文章