061_末晨曦Vue技术_过渡 & 动画之自定义过渡的类名

自定义过渡的类名

点击打开视频讲解更加详细

我们可以通过以下 attribute 来自定义过渡类名:

  • enter-class
  • enter-active-class
  • enter-to-class (2.1.8+)
  • leave-class
  • leave-active-class
  • leave-to-class (2.1.8+)

他们的优先级高于普通的类名,这对于 Vue 的过渡系统和其他第三方 CSS 动画库,如 Animate.css 结合使用十分有用。

首先安装Animate.css

npm install animate.css -- save

在main.js中引入

import Vue from 'vue'
import App from './App.vue'
import store from './store'
import router from './router'
//引入ElementUI组件库
import ElementUI from 'element-ui';
//引入ElementUI全部样式
import 'element-ui/lib/theme-chalk/index.css';
//引入animate.css动画库
import animated from 'animate.css' // npm install animate.css --save安装,再引入

//插件引入
// import {Plugin1,Plugin2} from './plugins/plugins.js'

// 全局组件注册  // 第一个解决组件之间的循环引用方式
// import HelloWorld from './components/HelloWorld'
// import Category from './components/Category'
// Vue.component('HelloWorld',HelloWorld)
// Vue.component('Category',Category)

Vue.config.productionTip = false

//使用ElementUI
Vue.use(ElementUI)
Vue.use(animated)

// Vue.use(Plugin1,'参数1')
// Vue.use(Plugin2,'参数2')

new Vue({
  store,
  router, 
  render: h => h(App),
}).$mount('#app')

完整案例:

<template>
  <div>
     自定义过渡的类名

      可以通过以下 attribute 来自定义过渡类名:

      enter-class
      enter-active-class
      enter-to-class (2.1.8+)
      leave-class
      leave-active-class
      leave-to-class (2.1.8+)

     安装Animate.css => npm install animate.css -- save
    <div id="example-3">
      <button @click="show = !show">
        Toggle render
      </button>
      <transition
        name="custom-classes-transition"
        enter-active-class="animate__animated animate__swing"
        leave-active-class="animate__animated animate__flash"
      >
        <p v-if="show">hello</p>
      </transition>
    </div>
  </div>
</template>
<script>
export default {
  name: 'home',
  data(){
    return {
       show:false
    } 
  },
  created(){
    
  },
  mounted() {
    
  },
  computed:{
    
  },
  methods:{
    
  }
}
</script>

<style scoped>

</style>

若对您有帮助,请点击跳转到B站一键三连哦!感谢支持!!!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue 3中的路由跳转过渡动画可以通过使用Vue过渡系统来实现。在路由跳转时,你可以通过给需要过渡的元素添加过渡类名来实现动画效果。 首先,在Vue 3中,你需要使用`&lt;transition&gt;`组件来包裹需要过渡的元素。在跳转到新页面时,你可以使用Vue Router提供的`&lt;RouterView&gt;`组件来渲染新页面的内容。 接下来,你可以在`&lt;transition&gt;`组件中定义不同的过渡效果。你可以使用Vue的内置的过渡类名,如`enter`、`leave`、`enter-active`、`leave-active`等,来定义元素进入和离开时的过渡效果。通过给元素添加这些类名,你可以使用CSS来定义相应的过渡动画。 以下是一个简单的示例,展示了如何使用Vue 3的路由跳转过渡动画: ```html &lt;template&gt; &lt;transition name=&quot;fade&quot;&gt; &lt;RouterView /&gt; &lt;/transition&gt; &lt;/template&gt; &lt;style&gt; .fade-enter { opacity: 0; } .fade-leave-to { opacity: 0; } .fade-enter-active, .fade-leave-active { transition: opacity 0.5s; } &lt;/style&gt; ``` 在上面的示例中,我们给`&lt;transition&gt;`组件添加了`name`属性,并设为&quot;fade&quot;。在CSS中,我们定义了`fade-enter`和`fade-leave-to`类来控制元素的透明度,并使用`fade-enter-active`和`fade-leave-active`类来定义过渡动画的持续时间。 当路由跳转时,新页面的内容将被包裹在`&lt;transition&gt;`组件中,并且会根据CSS的定义来显示过渡动画。 通过使用Vue过渡系统,你可以轻松地为Vue 3的路由跳转添加动画效果。希望这个简单的示例能帮助你更好地理解Vue 3中路由跳转过渡动画的实现方式。&lt;span class=&quot;em&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;em&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;em&quot;&gt;3&lt;/span&gt; #### 引用[.reference_title] - *1* *2* *3* [Vue3中实现路由跳转的过渡动画(一)](https://blog.csdn.net/fang_my/article/details/125578420)[target=&quot;_blank&quot; data-report-click={&quot;spm&quot;:&quot;1018.2226.3001.9630&quot;,&quot;extra&quot;:{&quot;utm_source&quot;:&quot;vip_chatgpt_common_search_pc_result&quot;,&quot;utm_medium&quot;:&quot;distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2&quot;}}] [.reference_item style=&quot;max-width: 100%&quot;] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

咬着拽天下的程序猿

心若释然,何惧万水千山!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值