Lab 11: Advanced Animations
Overview
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
Summary
Feature
Syntax
Browser Support
Last updated
