走马灯 Carousel

基本

  1. <za-carousel direction="left" @changeStart="handleChangeStart" @changeEnd="handleChangeEnd">
  2. <za-carousel-item :key="index" class="carousel-item-pic" v-for="(i, index) in ITEMS">
  3. <img :src="i.url" :alt="i.img" :draggable="false">
  4. </za-carousel-item>
  5. </za-carousel>

纵向

  1. <za-carousel height="48vw" direction="bottom" @changeStart="handleChangeStart" @changeEnd="handleChangeEnd">
  2. <za-carousel-item :key="index" class="carousel-item-pic" v-for="(i, index) in ITEMS">
  3. <img :src="i.url" :alt="i.img" :draggable="false">
  4. </za-carousel-item>
  5. </za-carousel>

循环轮播

  1. <za-carousel ref="carousel" direction="left" :swipeable="false" loop @changeStart="handleChangeStart" @changeEnd="handleChangeEnd">
  2. <za-carousel-item :key="index" class="carousel-item-pic" v-for="(i, index) in ITEMS">
  3. <img :src="i.url" :alt="i.img" :draggable="false">
  4. </za-carousel-item>
  5. </za-carousel>
  6. <div class="controls" style="text-align:center;padding-bottom:20px;">
  7. <za-button size="sm" @click="onJumpTo">无动画切换指定页</za-button>
  8. <za-button size="sm" style="margin-left:10px;" @click="onSlideTo">滑动到指定页</za-button>
  9. </div>

自动轮播

<za-carousel direction="left" :swipeable="false" loop auto-play>
  <za-carousel-item :key="index" v-for="(i, index) in ITEMS">
    <div class="carousel-item-pic">
      <img :src="i.url" :alt="i.img" :draggable="false">
    </div>
  </za-carousel-item>
</za-carousel>

Vue Script

<script name="vue">
const ITEMS = [
  {
    url: 'https://static.zhongan.com/website/health/zarm/images/banners/1.png',
    img: '1',
  },
  {
    url: 'https://static.zhongan.com/website/health/zarm/images/banners/2.png',
    img: '2',
  },
  {
    url: 'https://static.zhongan.com/website/health/zarm/images/banners/3.png',
    img: '3',
  },
];

export default {
  data() {
    return {
      ITEMS,
      i: {}
    }
  },
  methods: {
    handleChangeStart(index){
      console.log(index);
    },
    handleChangeEnd(index){
      console.log(index);
    },
    onJumpTo(){
      this.$refs.carousel.onJumpTo(0)
    },
    onSlideTo(){
      this.$refs.carousel.onSlideTo(2)
    }
  },
};
</script>

API

Carousel Attributes

属性类型默认值可选值/参数说明
directionstring'left''left', 'right', 'top', 'bottom'滑动方向
heightnumber, string高度
loopbooleanfalse是否循环
active-indexnumber0当前页面的索引
swipeablebooleantrue是否可拖拽
auto-playbooleanfalse是否自动轮播
auto-play-interval-timenumber3000自动轮播时间间隔,单位:毫秒
move-distance-rationumber0.5移动距离比例临界点
move-time-spannumber300移动时间跨度临界点,单位:毫秒
animation-durationnumber300动画执行时间,单位:毫秒

Carousel Events

事件名称说明回调参数
change-start动画开始时触发的事件index, 当前处于激活状态幻灯片的 index 值
change-end动画结束后触发的事件index, 动画结束时处于激活状态幻灯片的 index 值

Carousel 走马灯 - 图1