Lisi Linhart
Creative Frontend Developer
npm install wifi
npm install wifi
npm install wifi
npm install wifi
npm install wifi
.circle {
width: 200px;
height: 200px;
background: teal;
transform: scale(0.2);
}
.circle.animated {
animation: scaleUpAndFade 2s linear 0s 1 forwards;
}
@keyframes scaleUpAndFade {
from {
opacity: 1;
transform: scale(0.2);
}
to {
opacity: 0;
transform: scale(1);
}
}
const circle = document.querySelector(".circle");
circle.addEventListener('click', (e) => {
circle.classList.toggle('animated');
});.circle {
width: 200px;
height: 200px;
background: teal;
transform: scale(0.2);
}
const circle = document.querySelector(".circle");
circle.addEventListener('click', (e) => {
circle.animate([
{ transform: 'scale(0.2)', opacity: 1 },
{ transform: 'scale(1)', opacity: 0 },
], {
duration: 2000,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards'
});
});
// element.animate(keyframes, options);
const animation = document.querySelector(".apple").animate(
[
{ transform: 'translateY(0%)', easing: 'ease-in', offset: 0 },
{ transform: 'translateY(500%)', easing: 'ease-out', offset: .33 },
{ transform: 'translateY(420%)', easing: 'ease-in', offset: .5 },
{ transform: 'translateY(500%)', easing: 'ease-out', offset: .66 },
{ transform: 'translateY(460%)', easing: 'ease-in', offset: .82 },
{ transform: 'translateY(500%)', easing: 'ease-out', offset: .92 },
{ transform: 'translateY(480%)', easing: 'ease-in', offset: .97 },
{ transform: 'translateY(500%)', easing: 'ease-out', offset: 1 },
],
{
duration: 2000, // milliseconds
iterations: 1, // or Infinity
direction: 'normal', // 'alternate', 'reverse', 'alternate-reverse'
fill: 'forwards', // 'backwards', 'both', 'none', 'auto'
delay: 0, // milliseconds
endDelay: 0, // milliseconds
easing: 'linear', // 'ease', 'ease-in-out', 'ease-in', ...
}
);
tree.addEventListener('click', () => {
animation.currentTime = 0;
animation.play();
});
apple.addEventListener('click', () => {
animation.playbackRate += 0.2;
});
const animation = element.animate(/* animation */);
console.log(animation.playState); //"running"
animation.pause(); //"paused"
animation.play(); //"running"
animation.cancel(); //"idle"... jump to original state
animation.finish(); //"finished"...jump to end state
animation.reverse(); // play animation in reverse
animation.playbackRate = 1.5; // play faster
const animation = element.animate(/* animation */);
animation.onfinish = function() {
console.log("Animation finished");
};
animation.oncancel = animation.effect.target.remove();
if (window.matchMedia('(prefers-reduced-motion)')) {
document.getAnimations().forEach( // get all animations
(animation) => animation.cancel(); // cancel them
);
}
:root {
--duration: 0.8;
@media (prefers-reduced-motion: reduce) {
--duration: 0;
}
}
.element {
animation: fadeOut calc(var(--duration) * 1s) linear;
}Cross-Browser-Kompatibilität & SVG
Browser Renderer & DOM
native Animation vs externe Library
Basis für Browser
By Lisi Linhart
An intro to the Web Animations API