--- title: 'Document: animationcancel イベント' slug: Web/API/Document/animationcancel_event tags: - CSS Animations - CSS アニメーション - Document - Event - Reference - Web - animationcancel - イベント - ウェブ translation_of: Web/API/Document/animationcancel_event ---
animationcancel イベントは、 CSS アニメーションが予期せず中断されたときに発生します。言い換えれば、 {{domxref("Document/animationend_event", "animationend")}} イベントを送出せずに実行が停止するときはいつでもです。これは {{cssxref("animation-name")}} が変更されてアニメーションが削除されたり、動いているノードが CSS を使用して非表示にされた場合などに起こることがあります。したがって、直接または原因として、その包含ノードのいずれかが隠されています。
| バブリング | あり |
|---|---|
| キャンセル | 不可 |
| インターフェイス | {{domxref("AnimationEvent")}} |
| イベントハンドラープロパティ | {{domxref("GlobalEventHandlers/onanimationcancel","onanimationcancel")}} |
このイベントの本来の対象は、トランジションが適用された {{domxref("Element")}} です。このイベントを {{domxref("Document")}} インターフェイス上で待ち受けし、キャプチャやバブリングの局面で処理することができます。このイベントについて完全な詳細は、 HTMLElement: animationcancel イベントを参照してください。
このコードはリスナーに animationcancel イベントを追加します。
document.addEventListener('animationcancel', () => {
console.log('アニメーションが取り消されました');
});
同様に、 {{domxref("GlobalEventHandlers/onanimationcancel", "onanimationcancel")}} プロパティを addEventListener() の代わりに使用するとこうなります。
document.onanimationcancel = () => {
console.log('アニメーションが取り消されました');
};
| 仕様書 | 状態 | 備考 |
|---|---|---|
| {{SpecName("CSS3 Animations", "#eventdef-animationevent-animationcancel")}} | {{Spec2("CSS3 Animations")}} | 初回定義 |
{{Compat("api.Document.animationcancel_event")}}