3. semester
Animation
Animation
Animation
Animation
Style recalculation
Layout
Paint
Composite
Caused by some event
width,
margin,
left...
background,
box-shadow,
color...
transform,
opacity
1 frame
Animation
Aim for 60fps = (1000 / 60 ≈ 16,67ms)
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
Style recalculation
Layout
Paint
Composite
(1000ms / 60 ≈ 16,67ms)
Caused by some event
width,
margin,
left...
background,
box-shadow,
color...
transform,
opacity
Animation
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
Animation
Animation
div {
will-change: transform;
}
Animation
div {
will-change: transform;
}
Vi giver et hint til browseren om, at dette element ofte bliver animeret
(kun hvis animationen ikke er smooth)
Animation
div {
will-change: transform;
}
div:hover {
translate: 10px 10px;
}
Vi giver et hint til browseren om, at dette element ofte bliver animeret
(kun hvis animationen ikke er smooth)
Animation
Animation
Animation
For mange kompositlag foranlediger overbelastning for browseren
Animation
Animation
.line {
/*width: 20%;*/
transform: scaleX(.2);
}
Animation
Animation
Animation
Animation
Animation
Animation
Animation
Browsers can smartly eliminate unnecessary work by only dealing with what is actually visible on the screen
Animation
Animate on intersection
Animation
const elms = document.querySelectorAll('.element');
const config = {
rootMargin: '0px',
threshold: [0, .25, .75, 1]
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.intersectionRatio > .75) {
entry.target.classList.add('visible');
} else {
entry.target.classList.remove('visible');
}
});
}, config);
elms.forEach(elem => {
observer.observe(elem);
});
Se mere på MDN
Animation
Animation
Animation
Optimized composited scroll animations
Not blocking main thread
Loading...
Loading...
Loading...
.element {
animation: progress linear;
animation-timeline: scroll();
}
.element {
animation: reveal linear;
animation-timeline: view();
animation-range: cover 0% entry 100%;
}
section > * {
animation:
entry linear,
exit linear;
animation-timeline: view();
animation-range: [...];
}
ScrollTrigger