Skip to content

Animate 动画/动效

介绍

给子元素添加动画效果。

基础用法

html
<template>
  <nut-animate :show="show1" type="slide-right">
    <nut-button @click="onClick1()">单次动画</nut-button>
  </nut-animate>

  <nut-animate :show="show2" type="slide-right">
    <nut-button @click="onClick2()">多次触发</nut-button>
  </nut-animate>
</template>
ts
const show1 = ref(false);
const show2 = ref(false);

function onClick1() {
  show1.value = true;
}

function onClick2() {
  show2.value = true;

  setTimeout(() => {
    show2.value = false;
  }, 500);
}

循环动画

html
<template>
  <nut-animate type="shake" loop>
    <text>Shake 抖动</text>
  </nut-animate>

  <nut-animate type="ripple" loop>
    <text>Ripple 心跳</text>
  </nut-animate>

  <nut-animate type="breath" loop>
    <text>Breath 呼吸</text>
  </nut-animate>

  <nut-animate type="twinkle" loop>
    <text>Twinkle 水波</text>
  </nut-animate>

  <nut-animate type="flicker" loop>
    <text>Flicker 擦亮</text>
  </nut-animate>

  <nut-animate type="jump" loop>
    <text>Jump 跳跃</text>
  </nut-animate>

  <nut-animate type="float" loop>
    <text>Float 漂浮</text>
  </nut-animate>
</template>

点击触发

html
<template>
  <nut-animate type="slide-right" action="click">
    <text>由右向左划入</text>
  </nut-animate>

  <nut-animate type="slide-left" action="click">
    <text>由左向右划入</text>
  </nut-animate>

  <nut-animate type="slide-top" action="click">
    <text>由上至下划入</text>
  </nut-animate>

  <nut-animate type="slide-bottom" action="click">
    <text>由下至上划入</text>
  </nut-animate>
</template>

API

Props

参数说明类型可选值默认值
show控制动画,当值从 false 变为 true 时会触发一次动画boolean-false
type动画类型,见下方动画类型说明stringshake / ripple / breath / float / slide-right / slide-left / slide-top / slide-bottom / jump / twinkle / flicker-
loop是否循环执行boolean-false
duration动画时长(单位:ms)number / string-500
action触发方式(initial 初始化执行,click 点击执行)(不能与 show 同时使用)string-initial

动画类型

名称说明
shake抖动,建议 looptrue
ripple不循环是放大后缩小,循环则是心跳
breath呼吸,建议 looptrue
float漂浮,建议 looptrue
slide-right由右向左划入
slide-left由左向右划入
slide-top由上至下划入
slide-bottom由下至上划入
jump跳跃,建议 looptrue
twinkle水波,建议 looptrue
flicker擦亮,建议 looptrue

Events

事件名说明类型
animate动画触发() => void
click点击元素时触发(event: Event) => void

Slots

名称说明
default内容

MIT Licensed