CSS scroll-driven animations

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

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

The CSS scroll-driven animations module provides functionality that builds on the CSS animations module and Web Animations API. It allows you to animate property values along a scroll-based timeline rather than the default time-based document timeline. This means that you can animate an element by scrolling the element, its scroll container, or its root element, rather than just by the passing of time.

Scroll-driven animations in action

You can define the scroller that controls the animation either by naming the animation or with the {{cssxref("animation-timeline/scroll", "scroll()")}} or {{cssxref("animation-timeline/view()", "view()")}} functions.

html hidden live-sample___scroll_animation
css live-sample___scroll_animation
main {
  scroll-timeline: --main-timeline;
}

div {
  animation: background-animation linear;
  animation-timeline: scroll(nearest inline);
}

div::after {
  animation: shape-animation linear;
  animation-timeline: --main-timeline;
}
css hidden live-sample___scroll_animation

{{EmbedLiveSample("scroll_animation", "", "400px")}}

Scroll the element in the inline direction to see its background color change. Scroll it vertically to see the generated content move, spin, and change colors.

Reference

Properties

  • {{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")}}

Data types and values

  • {{cssxref("axis")}}
  • {{cssxref("timeline-range-name")}}

Functions

  • {{cssxref("animation-timeline/scroll", "scroll()")}}
  • {{cssxref("animation-timeline/view", "view()")}}

Interfaces

  • {{domxref("ScrollTimeline")}}
  • {{domxref("ViewTimeline")}}

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 animation triggers module
  • {{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")}}
  • CSS overflow module
  • {{glossary("Scroll container")}}
  • Scrollport
  • Web Animations API
  • {{domxref("Element.animate()")}}
  • {{domxref("Animation")}}
  • {{domxref("AnimationTimeline")}}
  • {{domxref("DocumentTimeline")}}
  • {{domxref("KeyframeEffect")}}

Specifications

{{Specifications}}

See also

  • Animate elements on scroll with scroll-driven animations via developer.chrome.com (2023)