ReasonJun

CSS : Animation 본문

Frontend/CSS

CSS : Animation

ReasonJun 2023. 6. 6. 12:57
728x90

In CSS, animations allow you to create dynamic and interactive effects by animating the values of CSS properties over a specified duration. With animations, you can bring elements to life by adding movement, transitions, and other visual transformations.

 

To create an animation, you typically define a set of keyframes that specify the values of CSS properties at various points in time. Keyframes are defined using the @keyframes rule. Each keyframe represents a specific point in the animation timeline and can have a percentage value (0% to 100%) or a keyword such as from (equivalent to 0%) or to (equivalent to 100%).

 

Here's an example that animates the opacity of an element:

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.element {
  animation-name: fadeIn;
  animation-duration: 2s;
}

In this example, the @keyframes rule defines an animation called fadeIn. It starts at an opacity of 0 (from keyframe) and gradually transitions to an opacity of 1 (to keyframe). The .element class then applies the animation using the animation-name property set to fadeIn and animation-duration property set to 2s (2 seconds).

 

CSS animations offer various properties to control the animation behavior:

  • animation-duration: Specifies the duration of the animation.
  • animation-delay: Defines a delay before the animation starts.
  • animation-timing-function: Specifies the timing function for the animation, controlling the acceleration and deceleration of the animation.
  • animation-iteration-count: Sets the number of times the animation should repeat or whether it should repeat indefinitely.
  • animation-direction: Determines whether the animation should play in the forward direction, reverse direction, or alternate between the two.
  • animation-fill-mode: Controls the styles applied to the element before and after the animation.

You can also combine multiple animations and apply them to different CSS properties. Furthermore, animations can be triggered by various events such as hover, click, or the loading of a web page using JavaScript.

 

CSS animations offer a powerful and efficient way to create engaging visual effects and interactions on the web. They provide a smoother experience compared to JavaScript-based animations and can be easily controlled and manipulated using CSS properties and media queries.

728x90

'Frontend > CSS' 카테고리의 다른 글

CSS : min-content, object-fit, letter-spacing, inset, grid, grid-template-columns, box-shadow  (0) 2023.06.13
CSS : media  (0) 2023.06.06
CSS : transition  (0) 2023.06.06
CSS : Stack order / flex  (0) 2023.06.05
CSS : position  (0) 2023.06.05
Comments