在vue中使用animate庫

<style>
  @keyframes bounce-in {
    0% {
      transform: scale(0);
    }
    50% {
      transform: scale(1.5)
    }
    100% {
      transform: scale(1);
    }
  }
  .fade-enter-active{
    transform-origin: left center;
    animation: bounce-in 1s;
  }
  .fade-leave-active{
    transform-origin: left center;
    animation: bounce-in 1s reverse;
  }
</style>
<div id='app'>
  <transition name='fade'>
    <div v-if='show'>hello world</div>
  </transition>
  <button @click='handleClick'>切換</button>
</div>

<script>
var vm = new Vue({
  el:'#app',
  data:{
    show:true
  },
  methods:{
    handleClick:function(){
      this.show = !this.show;
    }
  }
})
</script>

這是個放大的動畫效果,在vue裏面能不能不用fade-leave-active,fade-enter-active這樣的規定好的class,我要用自定義的可不能夠,能夠css

 

<style>
  .active{
    transform-origin: left center;
    animation: bounce-in 1s;
  }
  .leave{
    transform-origin: left center;
    animation: bounce-in 1s reverse;
  }
</style>

<transition
  name='fade'
  enter-active-class='active'
  leave-active-class='leave'
>
  <div v-if='show'>hello world</div>
</transition>

在transition裏面起本身的別名vue

 

既然能夠自定義本身的class,就可使用咱們的animate.css庫,animate.css庫是
https://daneden.github.io/animate.css/
這個庫提供了不少動畫效果,咱們若是要使用這個動畫效果,能夠下載下來
<script src="../vue.js"></script>
<link rel='stylesheet' type='text/css' href="../animate.css">
<div id='app'>
  <transition
    name='fade'
     enter-active-class='animated swing'     leave-active-class='animated shake'
  >
    <div v-if='show'>hello world</div>
  </transition>
  <button @click='handleClick'>切換</button>
</div>

<script>
var vm = new Vue({
  el:'#app',
  data:{
    show:true
  },
  methods:{
    handleClick:function(){
      this.show = !this.show;
    }
  }
})
</script>
引入animate,出場動畫,入場動畫就不用本身寫了,animated表示引入庫裏面的動畫,後面的swing,shake表示要引入的具體動畫名
 
用這個動畫庫的好處是不少複雜的效果就不用本身寫了,直接用庫裏面的動畫效果就能夠實現
相關文章
相關標籤/搜索