Lab 11: Advanced Animations

Time: 30 minutes | Level: Advanced | Docker: docker run -it --rm node:20-alpine sh

Overview

Master advanced animation techniques: scroll-driven animations with animation-timeline, View Transitions API, CSS motion path, staggered animations, and prefers-reduced-motion safe patterns.


Step 1: Scroll-Driven Animations — scroll()

/* Scroll progress indicator */
@keyframes progress-bar {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

.scroll-progress {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 4px;
  background: var(--color-primary);
  transform-origin: left center;
  
  /* Link animation to page scroll */
  animation: progress-bar linear both;
  animation-timeline: scroll(root block);
  /* scroll(scroller axis) */
  /* scroller: root | self | nearest | <element> */
  /* axis: block | inline | x | y */
}

/* Sticky header opacity change on scroll */
@keyframes header-fade {
  0%   { background: transparent; backdrop-filter: none; }
  100% { background: rgba(255,255,255,0.9); backdrop-filter: blur(10px); }
}

.header {
  animation: header-fade linear both;
  animation-timeline: scroll(root);
  animation-range: 0px 100px; /* start-offset end-offset */
}

/* Parallax effect */
@keyframes parallax-slow {
  from { transform: translateY(0); }
  to   { transform: translateY(-30%); }
}

.hero-background {
  animation: parallax-slow linear both;
  animation-timeline: scroll(root);
  animation-range: 0% 50vh; /* only during first 50vh of scroll */
}

Step 2: Scroll-Driven Animations — view()


Step 3: View Transitions API


Step 4: CSS Motion Path


Step 5: Staggered Animations


Step 6: prefers-reduced-motion — Safe Patterns


Step 7: WAAPI (Web Animations API)


Step 8: Capstone — Animation Timeline Calculator

(Create the file:)

📸 Verified Output:


Summary

Feature
Syntax
Browser Support

Scroll timeline

animation-timeline: scroll()

Chrome 115+, ~72%

View timeline

animation-timeline: view()

Chrome 115+, ~72%

animation-range

entry 0% entry 100%

Chrome 115+

View Transitions

document.startViewTransition()

Chrome 111+, ~75%

view-transition-name

Named element morph

Chrome 111+

Motion path

offset-path: path(...)

88%+

offset-distance

0% to 100%

88%+

Stagger

animation-delay: calc(var(--i) * 100ms)

Universal

WAAPI

element.animate([...], opts)

Universal

prefers-reduced-motion

@media (prefers-reduced-motion: reduce)

95%+

Last updated