Skip to content

xtf-motion

组件说明

xtf-motion 是为已有内容增加入场、循环、叠加和级联动画的容器,适用于活动入口、状态提醒及卡片焦点。它不负责渲染业务内容,只通过默认插槽包裹 xtf-buttonxtf-card 等现有组件。


基础用法

1. 基础入场

用于普通卡片的淡入效果:

vue
<template>
  <xtf-motion effect="fade-up" :loop="false">
    <xtf-card padding="md"><xtf-text text="订单已创建" /></xtf-card>
  </xtf-motion>
</template>
<script>
export default {}
</script>

2. 主题与循环

用于持续强调的操作入口:

vue
<template>
  <xtf-motion effect="pulse-glow" theme="success" :duration="1800">
    <xtf-button label="立即处理" @click="handleClick"
  /></xtf-motion>
</template>
<script>
export default {
  methods: {
    handleClick() {
      console.log('开始处理')
    }
  }
}
</script>

3. 多动画顺序播放

effects-mode="sequence" 会按数组顺序切换动画:

vue
<template>
  <xtf-motion block :effects="effects" effects-mode="sequence" :effects-gap="160" :duration="1000">
    <xtf-card padding="md"><xtf-text text="营销活动入口" /></xtf-card>
  </xtf-motion>
</template>
<script>
export default {
  data() {
    return { effects: ['fade-up', 'pulse-glow', 'laser-sweep'] }
  }
}
</script>

4. 子节点级联

默认插槽的直接子节点可依次开始动画:

vue
<template>
  <xtf-motion block effect="zoom-in" cascade :cascade-step="120" :loop="false">
    <xtf-text text="第一步" /><xtf-text text="第二步" /><xtf-button label="完成" @click="done"
  /></xtf-motion>
</template>
<script>
export default {
  methods: {
    done() {
      uni.showToast({ title: '已完成', icon: 'none' })
    }
  }
}
</script>

全部属性

属性类型默认值作用描述适用范围
effectString'pulse-glow'单个动画名单效果
effectsArray | String[]动画列表,可为空格、逗号或数组多效果
effectsModeString'parallel''parallel' 同时播放,'sequence' 顺序播放effects 多项时
effectsGapString | Number120顺序播放间隔(ms)顺序播放
themeString'primary'primary/success/warning/danger/info 主题色使用主题色
accentColorString''主强调色覆盖主题主色
accentColor2String''次强调色覆盖主题柔和色
durationString | Number2200动画时长,限制为 500-6000ms调整节奏
delayString | Number0初始延迟(ms)延后入场
loopBooleantrue是否无限循环持续强调
cascadeBooleanfalse是否让默认插槽直接子节点级联多项内容
cascadeStepString | Number120子节点级联间隔(ms)cascade 为真
playBooleantrue是否播放动画外部暂停动画
pausedBooleanfalse是否暂停,并会停止顺序计时器临时冻结
overlayBooleantrue是否渲染光晕、扫描线等特效层强视觉效果
overlayLayerString'below'覆盖层在内容上方或下方'above'/'below'
auraLayerString'below'光晕在内容上方或下方'above'/'below'
intensityString | Number1特效强度,限制为 0.6-1.8调整幅度
radiusString | Number28容器圆角包裹卡片
insetString | Number10内容外侧留白调整包裹间距
blockBooleanfalse是否占满可用宽度块级区域
customClassString''根节点自定义类名样式覆盖
customStyleString | Object''根节点自定义样式动态样式

事件

事件名称触发时机回调参数参数说明
click点击根容器时(event: Event)原始点击事件

事件使用示例

vue
<template>
  <xtf-motion effect="shockwave" theme="danger" @click="handleMotionClick">
    <xtf-button label="风险提示"
  /></xtf-motion>
</template>
<script>
export default {
  methods: {
    handleMotionClick(event) {
      console.log('motion click', event)
    }
  }
}
</script>

插槽

插槽名作用域参数说明
默认插槽动画包裹的业务内容;开启 cascade 时,直接子节点会按 cascadeStep 依次开始动画。

默认插槽示例

vue
<template>
  <xtf-motion block effect="fade-up" :loop="false" @click="handleClick">
    <view class="notice">库存已同步</view>
  </xtf-motion>
</template>
<script>
export default {
  methods: {
    handleClick(event) {
      console.log('motion click', event)
    }
  }
}
</script>

主题说明

  • 主色使用 var(--xtf-motion-accent),默认来自 --xtf-color-primary 等主题变量。
  • 次色和光晕使用 var(--xtf-motion-secondary)
  • 时长、圆角、内边距分别由 --xtf-motion-duration--xtf-motion-radius--xtf-motion-inset 控制。
  • overlay 为真时,特效层按 overlayLayerauraLayer 叠放。

如需全局调整主题,请在 xtf-config-provider 或主题配置中覆盖相关颜色变量。

MIT Licensed