24
loading...
This website collects cookies to deliver better user experience
Animations can make UI elements resemble the real world, making them smoothly change while giving the feeling of continuity, action, and progress instead of changing in a blink of an eye. — Patrícia Silva, “How to Make CSS Animations”
animation
shorthand property or the animation
sub-properties.animation
shorthand property is a shorthand for the eight animation
sub-properties. It prevents you from wasting time typing the sub-property names and animates elements that require all eight sub-properties:/* Here’s the syntax of the animation shorthand property */
.element {
animation: name duration timing-function delay iteration-count direction fill-mode play-state;
}
animation
shorthand property animates the element on the page with all eight sub-properties:animation
shorthand property and configure the element’s animation in CSS. It becomes useful when you don’t want to use all the sub-properties simultaneously or when you forget the order of arrangement in the animation property:/* Here’s the syntax of the animation sub-properties. */
.element {
animation-name: name;
animation-duration: duration;
animation-timing-function: timing-function;
animation-delay: delay;
animation-iteration-count: count;
animation-direction: direction;
animation-fill-mode: fill-mode;
animation-play-state: play-state;
}
animation
shorthand property and the animation
sub-properties together because they produce the same thing. They should be used individually based on what you are trying to achieve.animation-name
, animation-duration
, and animation-timing-function
sub-properties that should make the heartbeat.@keyframes
at-rule property is not configured yet:animation
shorthand property or its sub-properties, keyframes use a percentage to indicate the animation sequence.@keyframes
at-rule with the same name passed to the animation-name
property. In the heartbeat demo, the animation-name
is heartbeat
, so you must name the @keyframes
at-rule heartbeat
as well.@keyframes
at-rule contains a style list of keyframe selectors, specifying percentages for the animation when the keyframe occurs, and a block containing the styles for that keyframe:@keyframes heartbeat {
0% {
transform: scale(1) rotate(-45deg);
}
20% {
transform: scale(1.25) rotate(-45deg);
}
40% {
transform: scale(1.5) rotate(-45deg);
}
}
0%
indicates the first moment of the animation sequence while 100%
indicates the final state of the animation.@keyframes
, let’s include it in the heart demo and see if anything changes:@keyframes
at-rule to make the size of the heart scale from 0%
to 40%
, you set:scale(1.25)
scale(1.5)
rotate(-45deg)
was added to maintain the original direction of the heart you created with CSS.