Crafting UI
UI-Animation
Animation

The pixel pipeline
Style recalculation
Layout
Paint
Composite
Caused by some event
width,
margin,
left...
background,
box-shadow,
color...
transform,
opacity
The pixel pipeline
Style recalculation
Layout
Paint
Composite
Caused by some event
width,
margin,
left...
background,
box-shadow,
color...
transform,
opacity

Chrome DevTools: Performance Tab
Expensive
The pixel pipeline
Style recalculation
Layout
Paint
Composite
Caused by some event
width,
margin,
left...
background,
box-shadow,
color...
transform,
opacity
Animation

Chrome DevTools: Performance panel
Animation
Brugerne bemærker, når billedfrekvenser varierer.

Animer med følgende properties, hvis muligt
div {
transform: translate(n, n)
scale(n)
skew(ndeg)
rotate(ndeg);
translate: n n;
scale: n;
rotate: ndeg;
opacity: 0..1;
}
Animation
Animation
Subpixel-animation
Using transform
Changing layout properties
Zoomed ind
Animation
Eksempler
.line {
/*width: 20%;*/
transform: scaleX(.2);
}
.box {
rotate: 45deg;
translate: -50% -50%;
scale: 1.1;
}
.box:hover {
rotate: 0deg;
}
Individual Transforms
.box {
rotate: 45deg;
translate: -50% -50%;
scale: 1.1;
}
.box:hover {
rotate: 0deg;
}
Individual Transforms
Rækkefølgen er prædefineret.
Hvis du skal styre rækkefølgen, så brug transform-funktionen
1
2
3
Individual Transforms
Composition
Composition
Composition
Linear()
Easing
Linear()
Easing
Linear()
Easing

.object-1 {
--move-to: 100px;
}
.object-2 {
--move-to: 400px;
}
[class|="object"] {
animation: move 1s linear forwards;
}
@keyframes move {
to {
translate: var(--move-to);
}
}
We can do this
Or this
Custom Properties
dry
Loading...
Custom Properties
Custom Properties
Boolean Prop
.rotate {
--hover: 0;
rotate: calc( var(--hover) * 45deg );
&:hover {
--hover: 1;
}
}
Brug calc() til at gange variablen med 45deg
0 * 45deg = 0deg
1 * 45deg = 45deg
Custom Properties
Boolean Prop
.slide-out {
--open: 0;
translate: calc( var(--open) * 100% );
&.open {
--open: 1;
}
}
Brug calc() til at gange variablen med 100%
@property --colorPrimary {
syntax: '<color>';
}
@property
@property --colorPrimary {
syntax: '<color>';
initial-value: magenta;
}
@property
@property --colorPrimary {
syntax: '<color>';
initial-value: magenta;
inherits: false;
}
@property
@property
@property --colorPrimary {
syntax: '<color>';
initial-value: magenta;
inherits: false;
}
— typed Custom Properties
Loading...
@property
@property --colorPrimary {
syntax: '<color>';
initial-value: magenta;
inherits: false;
}
— typed Custom Properties
Loading...
@property
@property --colorPrimary {
syntax: '<color>';
initial-value: magenta;
inherits: false;
}
— typed Custom Properties
Loading...
Offset-path & Conic Gradient
Conic-gradient()
body {
height: 100svh;
background:
conic-gradient(red, blue);
}
Lad os bygge den sammen
(lad den blive åben)
Offset-path
Offset-path
.parent {
.child {
offset-path: border-box;
}
}
Offset-path
Offset-path
Animeret tal
Popover
Popover
<button popovertarget="popup">Open popup</button>
<div popover id="popup">
<h2>I'm a popup</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing.</p>
</div>
(lad den blive åben)
Popover
Popover
@starting-style {
...
}
transition-behavior: allow-discrete;
:popover-open {
...
}
Animation
Popover
@starting-style {
...
}
transition-behavior: allow-discrete;
[popover] {
opacity: 0;
translate: 0 -100%;
}
:popover-open {
opacity: 1;
translate: 0 0;
}
Animation
Popover
@starting-style {
...
}
transition-behavior: allow-discrete;
[popover] {
opacity: 0;
translate: 0 -100%;
}
:popover-open {
opacity: 1;
translate: 0 0;
}
Animation
Popover
@starting-style {
opacity: 0;
translate: 0 100%;
}
transition-behavior: allow-discrete;
[popover] {
opacity: 0;
translate: 0 -100%;
}
:popover-open {
opacity: 1;
translate: 0 0;
}
Exit state
Entry state
Open state
Popover
Exit state
Entry state
Open state
@starting-style
Loading...
@starting-style
Loading...
transition-behavior
Loading...
transition-behavior
Popover Pattern
UI Challange
Accordion
Find branchen "accordion" på vores GitHub-repository

Mål: Bygge "levende" sites
Scroll-driven animations
Scroll driven animation
Scroll driven animation
Loading...
.element {
animation: progress linear both;
animation-timeline: scroll(block root);
}
Scroll-driven animation
Brug dokumentet som tidslinje
.element {
animation: progress linear both;
animation-timeline: scroll(); /* nearest */
}
Scroll-driven animation
Brug dokumentet som tidslinje
.element {
animation: reveal linear both;
animation-timeline: view();
animation-range: entry 0% exit 100%;
}
Scroll-driven animation
Hold øje med et element ift. viewporten
Scroll-driven animation
Loading...
Scroll-driven animation
Loading...
Scroll-driven animation
Loading...
Scroll-driven animation
Loading...
Scroll-driven animation
h1 {
animation: ;
animation-timeline: ;
animation-range: ;
}
Scroll driven animation
Loading...
Optimized flip-animations
View transitions
View Transitions
Loading...
View Transitions
Loading...
View Transition
.box-1 {
view-transition-name: box-1;
}
.box-2 {
view-transition-name: box-2;
}
View Transition
.box-1 {
view-transition-name: box-1;
}
.box-2 {
view-transition-name: box-2;
}
btn.addEventListener("click", () => {
document.startViewTransition(_ => grid.classList.toggle("col-count"));
});
View Transition
.box-1 {
view-transition-name: box-1;
}
.box-2 {
view-transition-name: box-2;
}
btn.addEventListener("click", () => {
if (document.startViewTransition) {
document.startViewTransition(_ => grid.classList.toggle("col-count"));
} else {
grid.classList.toggle("col-count");
}
});
View Transition
.box-1 {
view-transition-name: box-1;
}
::view-transition-new(box-1) {
animation: scale-in .5s both;
}
::view-transition-old(box-1) {
animation: scale-in .5s both reverse;
}
Crafting UI: UI-animation
By Dannie Vinther
Crafting UI: UI-animation
Crafting UI w/ CSS
- 104