Animations are a huge part of making compelling web applications and sites.
Create gradual transitions between the values of specific CSS properties.
CSS transitions let you decide
which properties to animate by listing them explicitly
when the animation will start by setting a delay (seconds)
how long the transition will last by setting a duration
how the transition will run by defining a timing function
Specifies the name or names of the CSS properties to which transitions should be applied.
transition-property
.swa-flight {
transition-property: margin-left, margin-bottom;
}
transition
as shorthand.swa-flight {
transition: margin-left, margin-bottom;
}
if just declare the property, changes to the properties occur as usual.
List of properties can be animated
Using CSS transform property The transform CSS property lets you rotate, scale, skew, or translate an element. It modifies the coordinate space of the CSS visual formatting model. MDN transform doc
Specifies the duration over which transitions should occur.
transition-duration
.swa-flight {
transition-property: mrigin-left, margin-bottom;
transition-duration: 8s, 4s;
}
transition
as shorthand.swa-flight {
transition: width 8s, height 4s;
}
Specifies a function to define how intermediate values for properties are computed.
transition-timing-function
.swa-flight {
transition-property: margin-left, margin-bottom;
transition-duration: 8s, 4s;
transition-timing-function: cubic-bezier(0.51, 0.18, 0.79, 0.53), cubic-bezier(0.7, 0.21, 1, 1);
}
transition
as shorthand.swa-flight {
transition: margin-left 8s cubic-bezier(0.51, 0.18, 0.79, 0.53), margin-bottom
4s cubic-bezier(0.7, 0.21, 1, 1);
}
Defines how long to wait between the time a property is changed and the transition actually begins.
transition-delay
.swa-flight {
transition-property: margin-left, margin-bottom;
transition-duration: 8s, 4s;
transition-timing-function: cubic-bezier(0.51, 0.18, 0.79, 0.53), cubic-bezier(0.7, 0.21, 1, 1);
transition-delay: 0s, 4s;
}
transition
as shorthand.swa-flight {
transition: margin-left 8s cubic-bezier(0.51, 0.18, 0.79, 0.53), margin-bottom
4s cubic-bezier(0.7, 0.21, 1, 1) 4s;
}
Animations consist of two components, a style describing the CSS animation and a set of keyframes that indicate the start and end states of the animation’s style, as well as possible intermediate waypoints.
Below properties can be shorted as animation
property.
animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
animation-fill-mode
animation-play-state
The @keyframes
CSS at-rule controls the intermediate steps in a CSS animation sequence
animationiteration
, animationend
, animationstart
The Web Animations API lets us construct animations and control their playback with JavaScript.
Including duratiion, fill ... etc
It's a bundle of information including at the bare minimum a set of keys and the duration they need to be animated over.
Use the Animation Object’s methods to play, pause, seek, and control the animation’s playback direction and speed.
const drinking = document
.getElementById('liquid')
.animate([{ height: '100%' }, { height: '0' }], {
fill: 'forwards',
duration: 2000,
})
drinking.pause()
tells the browser that you wish to perform an animation and requests that the browser call a specified function to update an animation before the next repaint.
window.requestAnimationFrame(callback);