Skip to content

FadeInOut 淡入淡出

轮播式淡入淡出组件,支持自动播放、底部进度圆点,并可通过 progress 事件监听当前帧进度。

基础用法

幻灯片 1
幻灯片 2
幻灯片 3
查看代码
vue
<template>
    <div style="border: 1px solid #eee; border-radius: 8px; overflow: hidden; width: 30vw; height: 20vh">
        <FadeInOut v-model="index" :items="items" :duration="1500" :delay="3000" style="height: 100%">
            <template #default="{ item, index }">
                <div
                    style="height: 180px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 20px"
                    :style="{ background: item }"
                >
                    幻灯片 {{ index + 1 }}
                </div>
            </template>
        </FadeInOut>
    </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { FadeInOut } from "@a-drowned-fish/rox-v";

const index = ref(0);
const items = ["#646cff", "#42b883", "#ff7a45"];
</script>

Props

参数说明类型默认值
modelValue (v-model)当前索引number0
items轮播数据Array[]
delay每帧停留时长(ms)number5000
duration淡入淡出动画时长(ms)number1600
autoplay是否自动播放booleantrue
dotVisible是否显示圆点booleantrue
dotVisibleWhenOnlyOne仅一帧时是否仍显示圆点booleanfalse
dotClass圆点容器类名string""
dotItemClass单个圆点类名string""
dotGap圆点间距(px)number10
dotItemBg未激活圆点颜色string"rgba(255,255,255,0.4)"
activeDotItemBg激活圆点颜色string"#ffffff"

事件

事件名说明回调参数
update:modelValue索引变化(index: number) => void
progress当前帧切换进度(ratio: number) => void

插槽

插槽名子作用域说明
default{ item, index }每一帧的内容

基于 MIT 协议开源