CSS animation triggers

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

The CSS animation triggers module provides functionality to trigger standard time-based CSS animations when a specific timeline trigger occurs.

Scroll-triggered animations allow you to control when a regular time-based animation starts, pauses, or stops based on when a trigger activates or deactivates, without using JavaScript. This could include when a scrolling element enters or leaves a timeline range.

These ranges normally come from view progress timelines, enabling, for example, an animation to start when an element enters a scrollport and pause when it leaves the scrollport. Properties let you change the timeline range and control the active and activation ranges. Triggers can specify different actions when entering versus exiting the timeline range, allowing control over animation playback.

The animation triggers module also defines event triggers. When supported, these will activate timeline-based animations when specific DOM events occur.

Animation triggers in action

This example demonstrates scroll-triggered animations. Scroll the box up and down — the appearance of the "bouncer" text will trigger the ball's animation, and its disappearance will trigger the same animation in reverse. Scroll further, and the same process will repeat when the "another bouncer" text appears and then disappears from the scrollport.

html hidden live-sample___in-action
css hidden live-sample___in-action
css hidden live-sample___in-action

{{embedlivesample("in-action", "100%", 400)}}

We defined the animation triggers by specifying a {{cssxref("timeline-trigger-name")}} and {{cssxref("timeline-trigger-source")}} on the "bouncer" elements. The ball has a bouncing {{cssxref("animation")}} set on it twice. It also has an {{cssxref("animation-trigger")}} property set: this references the names of both triggers and the actions to perform when the animations are activated and deactivated. Activation and deactivation are caused by the "bouncer" elements coming into and out of view.

Reference

Properties

  • {{cssxref("animation-trigger")}}
  • {{cssxref("timeline-trigger")}} shorthand
  • {{cssxref("timeline-trigger-activation-range")}} shorthand
  • {{cssxref("timeline-trigger-activation-range-end")}}
  • {{cssxref("timeline-trigger-activation-range-start")}}
  • {{cssxref("timeline-trigger-active-range")}} shorthand
  • {{cssxref("timeline-trigger-active-range-end")}}
  • {{cssxref("timeline-trigger-active-range-start")}}
  • {{cssxref("timeline-trigger-name")}}
  • {{cssxref("timeline-trigger-source")}}
  • {{cssxref("trigger-scope")}}

The CSS animation triggers module also introduces the event-trigger, event-trigger-name, and event-trigger-source properties. Currently, no browsers support these features.

Data types and values

  • {{cssxref("<animation-action>")}}

Guides

Related concepts

  • CSS animations module
  • {{cssxref("animation-timeline")}}
  • {{cssxref("@keyframes")}} at-rule
  • [<keyframe-selector>](/en-US/docs/Web/CSS/Reference/Selectors/Keyframe_selectors)
  • CSS scroll-driven animations module
  • {{cssxref("animation-range")}} shorthand
  • {{cssxref("animation-range-end")}}
  • {{cssxref("animation-range-start")}}
  • {{cssxref("scroll-timeline")}} shorthand
  • {{cssxref("scroll-timeline-axis")}}
  • {{cssxref("scroll-timeline-name")}}
  • {{cssxref("timeline-scope")}}
  • {{cssxref("view-timeline")}} shorthand
  • {{cssxref("view-timeline-axis")}}
  • {{cssxref("view-timeline-inset")}}
  • {{cssxref("view-timeline-name")}}

Specifications

{{Specifications}}

See also