vue3でanimateを使ってみる

初めてページに入るときにアニメーション効果が表示されますが、これを実現するにはAppearanceとAppearance-active-classを使用します。

 <transition
    appear
    enter-active-class="animated tada"
    leave-active-class="animated bounceOutRight"
    appear-active-class="animated tada"
 >
    <p v-if="show">hello</p>
 </transition>
Animate.cssクラスを使用する場合、enter-active-class クラスと Leave-active-class クラスに開始クラスと終了クラスを設定し、アニメーション化された基本クラスを追加する必要があります。そうしないと機能しません。
 <transition
    enter-active-class="animated tada"
    leave-active-class="animated bounceOutRight"
 >
    <p v-if="show">hello</p>
 </transition>

 明示的な移行期間

<transition :duration="1000">...</transition>
入場時間と退場時間をカスタマイズします。
<transition :duration="{ enter: 500, leave: 800 }">...</transition>
アニメーションとトランジション

デフォルト:

<template>
<div>
  <button @click="isShow = !isShow">显示/隐藏</button>
  <transition>
    <h2 v-show="isShow">动画效果</h2>
  </transition>
</div>
</template>

js:

<script>
export default {
  data() {
    return {
      isShow: true,
    };
  },
};
</script>
 
<style scoped>
/* 动画 */
 
/* 1. 关键帧 (动画效果) */
@keyframes axisX {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0px);
  }
}
 
/* 2. 过渡类名 */
/* 开始 */
.v-enter-active {
  background: skyblue;
  animation: axisX 1s;
}
/* 结束 */
.v-leave-active {
  background: skyblue;
  animation: axisX 1s reverse;
}
</style>

トランジションアニメーションを使用する

<style>
/* 2. 过渡动画 */
/* 开始 */
.v-enter-active {
  animation: axisX 1s;
}
/* 结束 */
.v-leave-active {
  animation: axisX 1s reverse;
}
</style>
<transition name="" appear>
    <h2 v-show="isShow">动画效果</h2>
</transition>

(ページ開始時に表示され、遷移アニメーションが自動的に実行されます)

トランジションの名前を指定します

1 つのコンポーネント内の複数のアニメーションに適しています

デフォルトとの違いは次のとおりです。
1. name=nameValue
2. 開始/終了遷移クラス名の v は nameValue に置き換えられます。

トランジションエフェクト

 <div>
    <button @click="isShow = !isShow">显示/隐藏</button>
    <transition name="h2">
      <h2 v-show="isShow">动画效果</h2>
    </transition>
 </div>
<style>
h2 {
  background: yellow;
}
 
 
/* 过渡 */
/* 进入起点,离开终点 */
.h2-enter,
.h2-leave-to {
  transform: translateX(-100%);
}
 
/* 进入过程,离开过程 */
.h2-enter-active,
.h2-leave-active {
  transition: 0.5s linear;
}
 
/* 进入终点,离开起点 */
.h2-enter-to,
.h2-leave {
  transform: translateX(0px);
}
</style>

複数の要素間の遷移

<transition-group name="h2" appear="true">
  <h2 v-show="isShow" key="1">动画效果1</h2>
  <h2 v-show="!isShow" key="2">动画效果2</h2>
</transition-group>
<style>
/* 过渡 */
/* 进入起点,离开终点 */
.h2-enter,
.h2-leave-to {
  transform: translateX(-100%);
}
 
/* 进入过程,离开过程 */
.h2-enter-active,
.h2-leave-active {
  transition: 0.5s linear;
}
 
/* 进入终点,离开起点 */
.h2-enter-to,
.h2-leave {
  transform: translateX(0px);
}
</style>

おすすめ

転載: blog.csdn.net/irisMoon06/article/details/133266746