最近搜索

vue3 轮播图片 走马灯 carousel

浏览:29
管理员 2025-02-11 12:26

这是基础用法,底部的导航,鼠标移入 直接切换。或者是鼠标点击切换


image.png



<template>
  <div class="block text-center">
    <span class="demonstration">
      Switch when indicator is hovered (default)
    </span>
    <el-carousel height="150px">
      <el-carousel-item v-for="item in 4" :key="item">
        <h3 class="small justify-center" text="2xl">{{ item }}</h3>
      </el-carousel-item>
    </el-carousel>
  </div>
  <div class="block text-center" m="t-4">
    <span class="demonstration">Switch when indicator is clicked</span>
    <el-carousel trigger="click" height="150px">
      <el-carousel-item v-for="item in 4" :key="item">
        <h3 class="small justify-center" text="2xl">{{ item }}</h3>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<style scoped>
.demonstration {
  color: var(--el-text-color-secondary);
}

.el-carousel__item h3 {
  color: #475669;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>





左右移动的箭头一直存在。 always


<template>  <el-carousel :interval="5000" arrow="always">  

  <el-carousel-item v-for="item in 4" :key="item">      <h3 text="2xl" justify="center">{{ item }}</h3> 
     </el-carousel-item>  </el-carousel></template><style scoped>.el-carousel__item 
     
     h3 {  color: #475669;  opacity: 0.75;  line-height: 300px;  margin: 0;  text-align: center;}.el-carousel__item:nth-child(2n) {  background-color: #99a9bf;}.el-carousel__item:nth-child(2n + 1) {  background-color: #d3dce6;}</style>




Carousel API

Carousel Attributes

属性名说明类型Default
heightcarousel 的高度string''
initial-index初始状态激活的幻灯片的索引,从 0 开始number0
trigger指示器的触发方式enumhover
autoplay是否自动切换booleantrue
interval自动切换的时间间隔,单位为毫秒number3000
indicator-position指示器的位置enum''
arrow切换箭头的显示时机enumhover
typecarousel 的类型enum''
cardScale 2.7.8当 type 为 card时,二级卡的缩放大小number0.83
loop是否循环显示booleantrue
direction展示的方向enumhorizontal
pause-on-hover鼠标悬浮时暂停自动切换booleantrue
motion-blur 2.6.0添加动态模糊以给走马灯注入活力和流畅性。booleanfalse

Carousel Events

事件名说明类型
change当前展示的幻灯片切换时触发,它有两个参数, 一个是新幻灯片的索引,另一个是旧幻灯片的索引Function

Carousel Slots

插槽名说明子标签
default自定义默认内容Carousel-Item

Carousel Exposes

方法名说明类型
activeIndex 2.7.8当前幻灯片的索引number
setActiveItem手动切换幻灯片,传入需要切换的幻灯片的索引,从 0 开始;或相应 el-carousel-itemname 属性值Function
prev切换至上一张幻灯片Function
next切换至下一张幻灯片Function

Carousel-Item API

Carousel-Item Attributes

属性名说明类型默认值
name幻灯片的名字,可用作 setActiveItem 的参数string''
label该幻灯片所对应指示器的文本string / number''

Carousel-Item Slots

插槽名说明
default自定义默认内容


联系站长

站长微信:xiaomao0055

站长QQ:14496453