Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make blinking/flashing text with CSS 3

Currently, I have this code:

@-webkit-keyframes blinker {   from { opacity: 1.0; }   to { opacity: 0.0; } }  .waitingForConnection {   -webkit-animation-name: blinker;   -webkit-animation-iteration-count: infinite;   -webkit-animation-timing-function: cubic-bezier(.5, 0, 1, 1);   -webkit-animation-duration: 1.7s; } 

It blinks, but it only blinks in "one direction". I mean, it only fades out, and then it appears back with opacity: 1.0, then again fades out, appears again, and so on...

I would like it to fade out, and then "raise" from this fade back again to opacity: 1.0. Is that possible?

like image 630
ojek Avatar asked May 02 '13 17:05

ojek


People also ask

How do I make text flicker in HTML?

The HTML <blink> tag is used to create a blinking text that flashes slowly.


1 Answers

You are first setting opacity: 1; and then you are ending it on 0, so it starts from 0% and ends on 100%, so instead just set opacity to 0 at 50% and the rest will take care of itself.

Demo

.blink_me {    animation: blinker 1s linear infinite;  }    @keyframes blinker {    50% {      opacity: 0;    }  }
<div class="blink_me">BLINK ME</div>

Here, I am setting the animation duration to be 1 second, and then I am setting the timing to linear. That means it will be constant throughout. Last, I am using infinite. That means it will go on and on.

Note: If this doesn't work for you, use browser prefixes like -webkit, -moz and so on as required for animation and @keyframes. You can refer to my detailed code here


As commented, this won't work on older versions of Internet Explorer, and for that you need to use jQuery or JavaScript...

(function blink() {   $('.blink_me').fadeOut(500).fadeIn(500, blink); })(); 

Thanks to Alnitak for suggesting a better approach.

Demo (Blinker using jQuery)

like image 177
Mr. Alien Avatar answered Sep 22 '22 19:09

Mr. Alien