Skip to content

TransitionCollapse 折叠动画

介绍

专为高度折叠设计的过渡组件,内置内容测高层,动画更稳定。API 与 Transition 基本一致,适合折叠面板、列表展开收起等场景。

普通淡入、位移、缩放等动画请继续使用 Transition;需要高度折叠时优先选用本组件。

基础用法

通过 show 控制展示,name 设置折叠动画类型。

html
<vd-transition-collapse :show="true" name="collapse"></vd-transition-collapse>
<vd-transition-collapse :show="true" name="collapse-fade"></vd-transition-collapse>
<vd-transition-collapse :show="true" name="enter-left"></vd-transition-collapse>
<vd-transition-collapse :show="true" name="enter-right"></vd-transition-collapse>

自定义折叠高度

通过 collapse-height 设置收起后的高度,大于 0 时收起后仍保持可见(适合内容预览、展开更多等场景)。该属性走布局 CSS 变量,可配合主题单位做响应式。

html
<vd-transition-collapse
  :show="expanded"
  :collapse-height="48"
>
  <view>完整内容...</view>
</vd-transition-collapse>

混合动画

html
<vd-transition-collapse :show="true" :name="custom"></vd-transition-collapse>
ts
import type { TransitionCollapseName } from 'vital-design';

const custom: TransitionCollapseName = {
  enter: 'enter-right',
  leave: 'collapse-fade',
}

API

Props

参数说明类型默认值
show是否展示booleanfalse
name动画名称TransitionCollapseName'collapse'
collapse-height折叠后的高度;大于 0 时收起后仍保持可见Numeric0
duration动画时长TransitionDuration300
delay动画延时TransitionDuration0
immediate初始化时如为展示状态,是否立即触发动画booleantrue
lazy-render是否懒渲染booleantrue
cacheable是否缓存节点,缓存节点后,切换展示状态时不会重新渲染节点booleantrue
enter-from-class进入动画起始类名ClassValue-
enter-active-class进入动画进行中类名ClassValue-
enter-to-class进入动画结束类名ClassValue-
leave-from-class离开动画起始类名ClassValue-
leave-active-class离开动画进行中类名ClassValue-
leave-to-class离开动画结束类名ClassValue-
content-class内容节点类名ClassValue-
content-style内容节点样式StyleValue-

代替原始 Props

参数说明类型默认值
custom-id根节点idstring-
custom-class根节点类名ClassValue-
custom-style根节点样式StyleValue-

Events

事件名说明回调参数
click点击时触发MouseEvent
enter-from进入动画开始时触发-
enter-to进入动画进行时触发-
enter-end进入动画完成时触发-
leave-from离开动画开始时触发-
leave-to离开动画进行时触发-
leave-end离开动画完成时触发-
transitionend过渡动画结束时触发TransitionEvent

Slots

名称说明
default自定义内容

Expose

方法名说明参数返回值
enter执行进入动画-Promise<void>
leave执行离开动画-Promise<void>

类型定义

组件导出以下类型定义:

ts
import type {
  TransitionCollapseName,
  TransitionCollapseType,
  TransitionCollapseInstance,
  TransitionDuration,
} from 'vital-design';

赣ICP备2025061025号-1