zl程序教程

您现在的位置是:首页 >  前端

当前栏目

Vue: transition animation

Vue animation Transition
2023-09-11 14:16:16 时间
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="description" content="">
  <meta name="keywords" content="bait bark">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <title>Vehemence</title>
  <script src="dist/vue.global.js"></script>
  <style>
    .box {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100px;
      height: 100px;
    }

    .blue {
      background-color: lavender;
    }

    .green {
      background-color: green;
    }

    .transition {
      transition: background-color 2s linear;
    }
  </style>
</head>

<body>
  <div id="vale"></div>
  <template id="t1">
    <main class="box transition" :class="{green:isGreen,blue:isBlue}">main</main>
    <button @click="transition">btn</button>
  </template>
  <script>
    let vail = Vue.createApp({
      data () {
        return {
          isBlue: true,
          isGreen: false,
        }
      },
      template: '#t1',
      methods: {
        transition () {
          this.isBlue = !this.isBlue
          this.isGreen = !this.isGreen
        }
      }
    }).mount('#vale')
  </script>
</body>

</html>