Home  >  Article  >  Web Front-end  >  How to Create a CSS Fade In & Out \"Loading\" Text Animation Loop without JavaScript?

How to Create a CSS Fade In & Out \"Loading\" Text Animation Loop without JavaScript?

Susan Sarandon
Susan SarandonOriginal
2024-10-26 19:26:02539browse

How to Create a CSS Fade In & Out

Simple CSS Animation Loop: Fade In & Out "Loading" Text

To create a looping animation in CSS that fades in and out text without using JavaScript, consider the following:

<code class="css">@keyframes flickerAnimation {
  0%   { opacity:1; }
  50%  { opacity:0; }
  100% { opacity:1; }
}</code>

The @keyframes rule defines the animation itself. In this case, the animation simply changes the opacity of the element from fully opaque to fully transparent and back again.

<code class="css">.animate-flicker {
    opacity:1;  
    animation: flickerAnimation 1s infinite;
}</code>

The .animate-flicker class applies the animation to any element with that class. The animation property specifies the name of the animation, the duration of each iteration (in this case, 1 second), and whether the animation should repeat infinitely.

One thing to note is that the code above may not work in all browsers. To ensure compatibility with a wider range of browsers, you need to add the appropriate vendor prefixes to the animation property. For example:

<code class="css">.animate-flicker {
   -webkit-animation: flickerAnimation 1s infinite;
   -moz-animation: flickerAnimation 1s infinite;
   -o-animation: flickerAnimation 1s infinite;
    animation: flickerAnimation 1s infinite;
}</code>

With these vendor prefixes added, the animation should work in most modern browsers.

The above is the detailed content of How to Create a CSS Fade In & Out \"Loading\" Text Animation Loop without JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn