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

Susan Sarandon
Release: 2024-10-26 19:26:02
Original
552 people have browsed it

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>
Copy after login

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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!