Skip to content

Transition

基础用法

html

<view style="width: 100px; height: 100px">
  <pa-transition :show="show" :mode="mode">
    <view style="width: 100px; height: 100px; background-color: #009c5d"></view>
  </pa-transition>
</view>

<view class="grid grid-cols-2 gap-30 mt-30">
  <pa-button v-for="modeKey in modeList" :key="modeKey" block @click="onShow(modeKey)">
    {{ modeKey }}
  </pa-button>
</view>
ts

import { nextTick, ref } from 'vue'
import type { TransitionMode } from '../..'

const show = ref<boolean>(true)
const mode = ref<TransitionMode>('fade')

const modeList = ref<TransitionMode[]>([
  'fade',
  'zoom',
  'fade-zoom',
  'fade-up',
  'fade-down',
  'fade-left',
  'fade-right',
  'slide-up',
  'slide-down',
  'slide-left',
  'slide-right',
])

const onShow = async (newMode: TransitionMode) => {
  mode.value = newMode
  show.value = false
  await new Promise<void>((resolve) => {
    setTimeout(() => {
      resolve()
    }, 500)
  })
  await nextTick()
  show.value = true
}

Transition Props

参数说明类型默认值
show是否展示组件boolean-
mode使用的动画模式TransitionMode'fade'
duration动画的执行时间,单位msstring | number300
timingFunction使用的动画过渡函数CSSProperties['transitionTimingFunction']'ease-out'
destroyOnClose关闭是否销毁内部元素booleantrue
customClass自定义classstring-
customStyle自定义样式CSSProperties-

Transition Event

事件名参数
click()
beforeEnter:
enter:
afterEnter:
beforeLeave:
leave:
afterLeave:

Transition Slot

名称说明
default-

样式变量

🙈