Carousel 轮播 pass 0.0.13+

基础样式

基础用法以及 dot 指示器
tip:height 属性默认为100%

展开查看

提示

需要结合<mg-carousel-item> 组件使用

<template>
  <div class="first">
    <mg-carousel :dot='true' :height="'180px'">
      <mg-carousel-item v-for="i in 4">
        <div class="item">{{i}}</div>
      </mg-carousel-item>
    </mg-carousel>
  </div>

  <div class="line"></div>

  <div class="sec">
    <mg-carousel 
      :dot='true' 
      :height="'180px'" 
      :dot-position="'right'" 
      :direction="'vertical'"
      :dot-trigger="'hover'">

      <mg-carousel-item v-for="i in 4">
        <div class="item">{{i}}</div>
      </mg-carousel-item>

    </mg-carousel>
  </div>
</template>

<style>
.mg-carousel-item:nth-of-type(odd) .item{
  background-color: #8ac007;
}
.mg-carousel-item:nth-of-type(even) .item{
  background-color: #3eaf7c;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

无限滚动与箭头

有些抱歉的是 arrow 只会出现在水平方向...并未支持垂直方向的样式
小声说,其实主要是一上一下感觉不大好看

展开查看
<template>
  <mg-carousel :arrow="'hover'" :infinity="true" :height="'180px'">
    <mg-carousel-item v-for="i in 4">
      <div class="item">{{i}}</div>
    </mg-carousel-item>
  </mg-carousel>
</template>
1
2
3
4
5
6
7

卡片式的轮播

另一种样式,长下面这个样子...

展开查看
<template>
  <mg-carousel 
    :type="'card'" 
    :arrow="'always'" 
    :duration="800" 
    :infinity="true" 
    :height="'180px'">
      <mg-carousel-item v-for="i in 4">
        <div class="item" :style="{backgroundColor:colors[i - 1]}">{{i}}</div>
      </mg-carousel-item>
  </mg-carousel>
</template>
<script>
export default{
  data(){
    return{
      colors:['#8ac007','#3eaf7c','#e7c000','#859bff']
    }
  }
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

动画效果

除滚动外也可以使用渐变的方式,给 animate 属性传入 'fade'

展开查看
<template>
  <mg-carousel :arrow="'always'" :animate="'fade'" :height="'180px'">
    <mg-carousel-item v-for="i in 4">
      <div class="item" :style="{backgroundColor:colors[i - 1]}">{{i}}</div>
    </mg-carousel-item>
  </mg-carousel>
</template>
1
2
3
4
5
6
7
参数说明类型可选值默认值
height高度string-100%
initActiveIndex起始的indexnumber-0
autoplay是否自动播放boolean-true
interval播放间隔,msnumber-3000
duration过度动画的时长,msnumber-400
direction滚动方向stringhorizontal,verticalhorizontal
dot是否展示指示器boolean-false
dotTrigger指示器的触发方式stringhover,clickclick
dotPosition指示器展示的位置stringbottom,top,left,rightbottom
infinity无限滚动boolean-true
type卡片风格stringcard-
arrow何时展示箭头stringhover,never,alwaysnever
animate动画样式stringscroll,fadescroll
事件说明回参
next切换至下一张时触发当前活跃项的索引
prev切换至上一张时触发当前活跃项的索引
方法说明参数返回值
next切换至下一张--
prev切换至上一张--
setActive切换至指定索引number-