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 {
transform: rotate(45deg) translate(-50%, -50%) scale(1.3);
}
.box:hover {
transform: rotate(0deg);
}.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 );
transition: rotate .3s;
&:hover {
--hover: 1;
}
}Brug calc() til at gange variablen med 45deg
Boolean Prop
.slide-out {
--open: 0;
translate: calc( var(--open) * 100% );
transition: translate .4s;
&.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...