Skip to Content
Vueを学ぶ
book

Vueを学ぶ

by Maya Shavin
March 2025
Intermediate to advanced
350 pages
5h 20m
Japanese
O'Reilly Media, Inc.
Content preview from Vueを学ぶ

第10章. Vueのトランジションとアニメーション

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

これまで、適切なステート管理によるルートやデータフローの処理など、動作するVueアプリケーションを構築するための重要な側面について説明してきた。この章では、ユーザ体験を向上させるためのVue独自の機能であるアニメーションとトランジションについて、トランジション・コンポーネント、フック、CSSを使用して説明する。

CSSトランジションとCSSアニメーションを理解する

CSSアニメーションは、特定の要素やコンポーネントの状態変化による視覚的要素であり、状態の数に制限はない。CSSアニメーションは、明示的なトリガーなしに自動的に開始し、ループに入ることができる。対照的に、CSSトランジションは、ボタンの平均からホバー、ツールチップの非表示から表示といった、2つの状態間の変化のみに反応するアニメーションである。CSSアニメーションを定義するには、多くの場合、@keyframes 規則を使用し、それをターゲット要素に適用するにはanimationプロパティを使ってターゲット要素に適用する。例えば、 ような単純なアニメーション効果を定義することができる:

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0px rgba(0, 0, 0, 0.5);
  }
  100% {
    box-shadow: 0 0 0 20px rgba(0, 0, 0, 0);
  }
}

.button {
  animation: pulse 2s infinite;
  box-shadow: 0px 0px 1px 1px #0000001a;
}

シンプルなアニメーション・エフェクト、pulse を定義し、button クラスを持つ要素に適用した。ボックス・シャドウがループで拡大・縮小し、2秒間続く。このエフェクトは、要素がDOMに存在すれば無限ループする。

A screenshot displays a button with a pulse effect
図10-1. 不定パルスのアニメーション効果

一方、transition プロパティを使用して、ユーザが特定の要素にマウスを合わせたときの遷移効果を定義することができる :

.button {
  transition: background-color 0.5s ease-in-out;
}

.button:hover {
  background-color: #ff0000;
}

このコードでは、button 要素にシンプルなトランジション効果を作成している。背景色は、0.5 秒の遅延で、ホバーリング時にデフォルトの色から赤に変わり、ease-in-out のスムージング効果を持つ。また、JavaScript やその他のアニメーションライブラリを使用して、JavaScript を使用してトランジションやアニメーションをプログラムで定義することもできる 。

トランジションとアニメーションは、ユーザがアプリケーションを使用する際に非常にスムーズな体験を提供する。しかし、トランジションやアニメーションを扱うことは、時に困難な場合がある。Vueはビューレイヤーにフォーカスしたフレームワークとして、CSSやJavaScriptを使ってコンポーネントやルートにスムーズで美しいアニメーションやトランジション効果を作成するためのAPIセットを提供している。そのひとつが ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

エンジニアが学ぶ会計システムの「知識」と「技術」

エンジニアが学ぶ会計システムの「知識」と「技術」

広川 敬祐, 五島 伸二, 小田 恭彦, 大塚 晃, 川勝 健司
グリーンなソフトウェア開発

グリーンなソフトウェア開発

Anne Currie, Sarah Hsu, Sara Bergman
強力なPython

強力なPython

Aaron Maxwell

Publisher Resources

ISBN: 9798341626102