Vue中CSS动画原理

原理:CSS3中的transition属性

<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta charset="utf-8">
  <title>Vue中CSS动画原理</title>
  <script src="./vue.js"></script>
  <style media="screen">
    .fade-enter,
    .fade-leave-to{
      opacity:0;
    }
    .fade-enter-active,
    .fade-leave-active{
      transition:opacity 3s;
    }
  </style>
</head>

<body>
  <div id="root">
    <transition name="fade">
      <div v-if="show">
        hello world
      </div>
    </transition>
    <button @click="handleClick">change</button>
  </div>
  <script type="text/javascript">
    var vm = new Vue({
      el: '#root',
      data: {
        show: true
      },
      methods: {
        handleClick: function() {
          this.show = !this.show
        }
      }
    })
  </script>
</body>

</html>

推荐阅读更多精彩内容