3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Vue3】アニメーションの開始終了イベントを取得する

Last updated at Posted at 2022-09-28

はじめに

軽くハマったので備忘録として書きます。
結論としては animationstart/end ではなく trasitionstart/end を使うことで動作しました。

作りたいもの

  • 要素の回転するときにアニメーションさせる
  • 回転中かどうかを検知して他の要素を制御する

間違い

<template>
  <div
    class="transition"
    :style="{ transform: `rotate(${angle}deg)` }"
    @animationstart="rotating = true"
    @animationend="rotating = false"
  >
    ターゲット
  </div>
  <button @click="angle += 90">回転</button>
  <div v-if="rotating">
    回転中
  </div>
</template>

<script setup>
  const angle = ref(0)
  const rotating = ref(false)
</script>

正解

<template>
  <div
    class="transition"
    :style="{ transform: `rotate(${angle}deg)` }"
-   @animationstart="rotating = true"
-   @animationend="rotating = false"
+   @trasitionstart="rotating = true"
+   @trasitionend="rotating = false"
  >
    ターゲット
  </div>
  <button @click="angle += 90">回転</button>
  <div v-if="rotating">
    回転中
  </div>
</template>

<script setup>
  const angle = ref(0)
  const rotating = ref(false)
</script>

参考

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?