vue3动画效果

引入了 Animate.css 动画库 附链接

安装
 npm install animate.css --save

全局引入 --main.js

import "animate.css";

就可以使用了

注意:将类名Animate__animated与其他动画名称一起写,单个动画名称不要忘记Animate__前缀!

<p class="animate__animated animate__XXXXX">动画</p>

使用

1.切换页面时加入【淡入淡出】动画,如:

 <transition  appear
        name="animate__animated animate__bounce"
        enter-active-class="animate__fadeIn"
      >
        <!--  leave-active-class="animate__fadeIn" -->
        <router-view />
      </transition>

2.点赞、关注等切换图标,如:

<!-- 关注 -->
    <div @click="followClick" class="follow">
      <i v-if="!follow && followFirst" class="iconfont iconguanzhudianpu"></i>
      <i v-if="follow && followFirst" class="iconfont iconyiguanzhu"></i>

      <i
        v-if="!follow && !followFirst"
        class="iconfont iconguanzhudianpu animate__animated animate__pulse"
      ></i>
      <i
        v-if="follow && !followFirst"
        class="iconfont iconyiguanzhu animate__animated animate__pulse"
      ></i>
      <p>关注</p>
    </div>

为了刚进入页面时不跳动画写得有点繁琐。

3.头像下方导航块的出现隐藏,需要【加速动画】效果,可以在类名 animate__faster ,如:

<!-- 头像下拉框 -->
  <transition
    name="animate__animated animate__bounce"
    enter-active-class="animate__fadeIn animate__faster"
    leave-active-class="animate__fadeOut animate__faster"
  >
    <!-- leave-active-class="animate__slideOutDown" -->
    <AvatarAlart
      v-show="AvatarAlartShow"
      @mouseover="AvatarAlartChange"
      @mouseleave="AvatarAlartShow = false"
      class="avatar-alart"
      :usertInfo="usertInfo"
    />
  </transition>

4.精准控制动画播放时间,可以在类名 -2s ,如:

<div class="animate__animated animate__bounce animate__delay-2s">以2秒播放完毕</div>

5.需要反复播放也是可以的,请在类名加入 __repeat-2 ,如:

<div class="animate__animated animate__bounce animate__repeat-2">重复2次</div>
  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue中可以使用第三方库或者自己编写loading动画组件来实现loading效果。以下是一个简单的loading组件示例: ```html <template> <div class="loading-container" v-if="loading"> <div class="loading-wrapper"> <div class="loading-spinner"></div> <div class="loading-text">{{ text }}</div> </div> </div> </template> <script> export default { props: { loading: { type: Boolean, default: false }, text: { type: String, default: '加载中...' } } } </script> <style> .loading-container { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); z-index: 9999; display: flex; justify-content: center; align-items: center; } .loading-wrapper { display: flex; align-items: center; } .loading-spinner { border: 4px solid rgba(255, 255, 255, 0.3); border-top-color: #fff; border-radius: 50%; width: 40px; height: 40px; animation: spin 0.8s ease-in-out infinite; margin-right: 10px; } .loading-text { color: #fff; font-size: 16px; } @keyframes spin { to { transform: rotate(360deg); } } </style> ``` 使用时,只需要在需要loading效果的组件中引入该组件并传入loading和text属性即可: ```html <template> <div> <loading :loading="loading" text="加载中..."></loading> <!-- 其他内容 --> </div> </template> <script> import Loading from '@/components/Loading.vue' export default { components: { Loading }, data() { return { loading: false } }, methods: { fetchData() { this.loading = true // 发送请求,获取数据 // ... this.loading = false } } } </script> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值