7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Vue.jsのtransitionでenterのアニメーションが適用されない【Vue3】

Last updated at Posted at 2022-01-05

ハンバーガーメニュークリックでモーダルが表示される仕様を作成しようとし、下記コードを記述しました。

<template>
  <div>
      <div class="menu_btn" @click="ActiveBtn = !ActiveBtn">
        <span class="line_01"></span>
        <span class="line_02"></span>
        <span class="line_03"></span>
      </div>
      <transition name="menu" appear>
        <Menubar v-if="ActiveBtn" class="menu" />
      </transition>
  </div>
</template>

<script>
export default {
data() {
    return {
      ActiveBtn: false,
    };
  },
};
</script>

<style lang="scss" scoped>
// アニメーションCSS ハンバーガーメニューのCSSは割愛
.menu-enter-active,
.menu-leave-active {
  transition: all 0.4s;
}
.menu-enter,
.menu-leave-to {
  opacity: 0;
}
.menu-enter-to,
.menu-leave {
  opacity: 1;
}
</style>

ハンバーガーメニューをクリックするとふわっと現れ、
もう一度クリックするとふわっと消えるようにしたかったのですが、
どうもふわっと現れる方(enter)の方のアニメーションが適用されません。

こちらの記事を参考にし、appear属性が入っていなかったのでtransitionに追加してみましたが、特に変化はありませんでした。
Vue.js の enter トランジション/アニメーションが適用されない

解決策

Vue3だと、enterのアニメーションCSSの記述が、下記に変更になったようです。

Vue2
v-enter

Vue3
v-enter-from

これでenterのアニメーションも適用されました!!
かなり詰まったので残しておきます。。

参考サイト

Vue.jsで下からフェードインして表示されるようなアニメーションを付けたい。

7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?