UI-Animation
Animation
Style recalculation
Layout
Paint
Composite
Caused by some event
width,
margin,
left...
background,
box-shadow,
color...
transform,
opacity
Style recalculation
Layout
Paint
Composite
Caused by some event
width,
margin,
left...
background,
box-shadow,
color...
transform,
opacity
Chrome DevTools: Performance Tab
Expensive
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.
div {
transform: translate(n, n)
scale(n)
skew(ndeg)
rotate(ndeg);
translate: n n;
scale: n;
rotate: ndeg;
opacity: 0..1;
}
Animation
Animation
Animation
.line {
/*width: 20%;*/
transform: scaleX(.2);
}
.box {
rotate: 45deg;
translate: -50% -50%;
scale: 1.1;
}
.box:hover {
rotate: 0deg;
}
.box {
rotate: 45deg;
translate: -50% -50%;
scale: 1.1;
}
.box:hover {
rotate: 0deg;
}
Rækkefølgen er prædefineret.
Hvis du skal styre rækkefølgen, så brug transform-funktionen
1
2
3
.object-1 {
--move-to: 100px;
}
.object-2 {
--move-to: 400px;
}
[class|="object"] {
animation: move 1s linear forwards;
}
@keyframes move {
to {
translate: var(--move-to);
}
}
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
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 --colorPrimary {
syntax: '<color>';
initial-value: magenta;
}
@property --colorPrimary {
syntax: '<color>';
initial-value: magenta;
inherits: false;
}
@property --colorPrimary {
syntax: '<color>';
initial-value: magenta;
inherits: false;
}
@property --colorPrimary {
syntax: '<color>';
initial-value: magenta;
inherits: false;
}
@property --colorPrimary {
syntax: '<color>';
initial-value: magenta;
inherits: false;
}
body {
height: 100svh;
background:
conic-gradient(red, blue);
}
(lad den blive åben)
.parent {
.child {
offset-path: border-box;
}
}
<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)
@starting-style {
...
}
transition-behavior: allow-discrete;
:popover-open {
...
}
Animation
@starting-style {
...
}
transition-behavior: allow-discrete;
[popover] {
opacity: 0;
translate: 0 -100%;
}
:popover-open {
opacity: 1;
translate: 0 0;
}
Animation
@starting-style {
...
}
transition-behavior: allow-discrete;
[popover] {
opacity: 0;
translate: 0 -100%;
}
:popover-open {
opacity: 1;
translate: 0 0;
}
Animation
@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
Exit state
Entry state
Open state
Loading...
Loading...
Loading...
UI Challange
Find branchen "accordion" på vores GitHub-repository
Mål: Bygge "levende" sites
Loading...
.element {
animation: progress linear both;
animation-timeline: scroll(block root);
}
.element {
animation: progress linear both;
animation-timeline: scroll(); /* nearest */
}
.element {
animation: reveal linear both;
animation-timeline: view();
animation-range: entry 0% exit 100%;
}
Loading...
Loading...
Loading...
Loading...
h1 {
animation: ;
animation-timeline: ;
animation-range: ;
}
Loading...
Optimized flip-animations
Loading...
Loading...
.box-1 {
view-transition-name: box-1;
}
.box-2 {
view-transition-name: box-2;
}
.box-1 {
view-transition-name: box-1;
}
.box-2 {
view-transition-name: box-2;
}
btn.addEventListener("click", () => {
document.startViewTransition(_ => grid.classList.toggle("col-count"));
});
.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");
}
});
.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;
}