Beyond Static: CSS Animation
Sobre a Aula

Understanding keyframes

“Keyframes” are key points in CSS animations. They are frames that define specific states, indicating the beginning, middle, and end of the animation.

Imagine a slideshow: the first keyframe displays the initial image, the last one displays the final image. The intermediates define smooth transitions between these states.

In code, it’s simple. Consider the following example:

@keyframes slide {
  0% { opacity: 0; transform: translateX(-100%); }
  50% { opacity: 0.5; transform: translateX(0); }
  100% { opacity: 1; transform: translateX(100%); }
}

.slide-container {
  animation: slide 3s infinite;
}

Here, @keyframes slide defines the animation. At the beginning (0%), the opacity is 0, and the element is off-screen. In the middle (50%), the opacity is 0.5, and the element slides onto the screen.

At the end (100%), the opacity is 1, and the element is off-screen again. animation: slide 3s infinite; applies the animation to the element with the class slide-container, taking 3 seconds to complete and repeating infinitely.

Keyframes are like instructions to tell the story of your animation, shaping the visual experience in a simple yet powerful way.

Entrar na conversa
Rolar para cima