Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple CSS Animation Loop – Fading In & Out "Loading" Text

Tags:

css

animation

Without Javascript, I'd like to make a simple looping CSS animation class that fades text in and out, infinitely. I don't know a lot about CSS animations, so I haven't figured it out yet, but here's how far I've gotten:

@keyframes flickerAnimation { /* flame pulses */   0%   { opacity:1; }   50%  { opacity:0; }   100% { opacity:1; } } .animate-flicker {     opacity:1;       animation: flickerAnimation 1s infinite; } 
like image 964
ac360 Avatar asked Jun 01 '14 22:06

ac360


People also ask

How do you animate a fade in CSS?

In the CSS, use the @keyframes rule paired with fadeIn. At 0%, set the opacity to 0. At 100%, set the opacity to 1. This creates the fade-in effect.

How do I fade in and fade out in CSS?

The jQuery fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in. If the elements are faded in, fadeToggle() will fade them out.

How do I fade a div in CSS?

Use animation and transition property to create a fade-in effect on page load using CSS. Method 1: Using CSS animation property: A CSS animation is defined with 2 keyframes. One with the opacity set to 0, the other with the opacity set to 1.


1 Answers

As King King said, you must add the browser specific prefix. This should cover most browsers:

@keyframes flickerAnimation {    0%   { opacity:1; }    50%  { opacity:0; }    100% { opacity:1; }  }  @-o-keyframes flickerAnimation{    0%   { opacity:1; }    50%  { opacity:0; }    100% { opacity:1; }  }  @-moz-keyframes flickerAnimation{    0%   { opacity:1; }    50%  { opacity:0; }    100% { opacity:1; }  }  @-webkit-keyframes flickerAnimation{    0%   { opacity:1; }    50%  { opacity:0; }    100% { opacity:1; }  }  .animate-flicker {     -webkit-animation: flickerAnimation 1s infinite;     -moz-animation: flickerAnimation 1s infinite;     -o-animation: flickerAnimation 1s infinite;      animation: flickerAnimation 1s infinite;  }
<div class="animate-flicker">Loading...</div>
like image 97
touko Avatar answered Sep 18 '22 16:09

touko