This question already has answers here:
Alternative for <blink>
(14 answers)
Closed 9 years ago.
I am making a website and I want a hyperlink on the page to blink. It doens't matter how fast it does, only not too slow. It would also be cool if I could make it blink in different colors.
I have tried using text-decoration:blink; in css, but that didn't work.
I've added this to the css-file, but now what?:
blink {
-webkit-animation-name: blink;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: cubic-bezier(1.0,0,0,1.0);
-webkit-animation-duration: 1s;
}
Doesn't seem to work
You can do this pretty easily with CSS animations.
a {
animation-duration: 400ms;
animation-name: blink;
animation-iteration-count: infinite;
animation-direction: alternate;
}
#keyframes blink {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
You can also extend it to change colors. With something like:
#keyframes blink {
0% {
opacity: 1;
color: pink;
}
25% {
color: green;
opacity: 0;
}
50% {
opacity: 1;
color: blue;
}
75% {
opacity: 0;
color: orange;
}
100% {
opacity: 1;
color: pink;
}
}
Make sure to add vendor prefixes
Demo: http://codepen.io/pstenstrm/pen/yKJoe
Update
To remove the fading effect you can do:
b {
animation-duration: 1000ms;
animation-name: tgle;
animation-iteration-count: infinite;
}
#keyframes tgle {
0% {
opacity: 0;
}
49.99% {
opacity: 0;
}
50% {
opacity: 1;
}
99.99% {
opacity: 1;
}
100% {
opacity: 0;
}
}
This is also a useful trick when animating image-sprites
Its easy to make a text blink:
window.setInterval(function() {
$('#blinkText').toggle();
}, 300);
and in html, just give as follows:
<p id="blinkText">Text blinking</p>
You seem to have copied code from the accepted answer to Blink not working in Chrome. The answer is wrong, however, and only tries to address WebKit browsers. The following code works in WebKit browsers, in modern Firefox, and in IE 10+ (I have set the parameters to simulate the way the classic <blink> worked):
#keyframes blink {
from { opacity: 1; }
to { opacity: 0; }
}
#-webkit-keyframes blink {
from { opacity: 1; }
to { opacity: 0; }
}
blink {
animation-name: blink;
animation-duration: 1s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
-webkit-animation-name: blink;
-webkit-animation-duration: 1s;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-iteration-count: infinite;
}
For a real cross-browser solution, you need JavaScript. It’s straighforward timed changes; see e.g. some answers to Text blinking jQuery.
Related
I'm trying to make a CSS animation were a word fades out, another words replaces it and the new word fades in. Can't seem to figure out the correct way to do it. Here's my code:
HTML
<span class="words"></span>
CSS
.words:before {
content: "one";
animation-name: replacement;
animation-duration: 2s;
animation-timing-function: ease-out;
animation-iteration-count: infinite;
animation-direction: alternate;
}
#keyframes replacement {
0% {
opacity: 0;
}
100% {
opacity: 1;
content: "two";
}
}
https://jsfiddle.net/fp2h6q4L/
Try this CSS
.words:before {
opacity:0;
content: "one";
animation-name: replacement;
animation-duration: 4s;
animation-timing-function: ease-out;
animation-iteration-count: infinite;
animation-direction: absolute;
}
#keyframes replacement {
0%{
opacity: 1;
}
50%{
opacity:0;
}
100%{
content:"two";
opacity:1;
}
}
<span class="words"></span>
If you want to do this with pure CSS, you'll probably need to define a second animation to change the text and then set the delay on that one to run when opacity is 0 so that the abrupt change is hidden.
I have a very simple animation that fades out and shrinks a div.
But the problem is that when the animation finishes it goes back to the start and stays there.
div {
background-color: red;
height: 80px;
}
.fade-out {
animation-name: fade-out;
animation-duration: 2s;
}
#keyframes fade-out {
0% { opacity: 1; }
50% { opacity: 0; }
100% { opacity: 0; height: 0;}
}
<div class="fade-out">Style Test</div>
If you add animation-fill-mode: forwards; to your .fade-out rule it will fix your animation.
animation-fill-mode specifies how CSS rules should be applied before and after executing the animation. The default is none which means that before and after the animation is executed, it will not apply any of the animation styles. That's why you're seeing it revert to the pre-animation state.
forwards tells the browser to retain the styles from the last keyframe. That's what you're looking for.
See the MDN docs for more information.
div {
background-color: red;
height: 80px;
}
.fade-out {
animation-name: fade-out;
animation-duration: 2s;
animation-fill-mode: forwards;
}
#keyframes fade-out {
0% { opacity: 1; }
50% { opacity: 0; }
100% { opacity: 0; height: 0;}
}
<div class="fade-out">Style Test</div>
Use animation-fill-mode property
.fade-out {
animation-name: fade-out;
animation-duration: 2s;
animation-fill-mode: forwards
}
I've created a div with a background image in css and I want the div/image to have an automatic fade in and fade out effect.
I've gathered the css animation for this to work however I have no idea as to how I can combine the css of the animation with my current div's css. So here is what I have so far
HTML
<div id="image"></div>
CSS
div.image {
content:url(http://www.google.com/images/srpr/logo3w.png);
float:left;
}
Animation CSS
#-webkit-keyframes blink {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#-moz-keyframes blink {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#-o-keyframes blink {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
img {
-webkit-animation: blink 1s;
-webkit-animation-iteration-count: infinite;
-moz-animation: blink 1s;
-moz-animation-iteration-count: infinite;
-o-animation: blink 1s;
-o-animation-iteration-count: infinite;
}
You need to target the div with the background image.
#image targets <div id="image">
.image targets <div class="image">
img targets <img>
You can read more on CSS selectors over at MDN.
Have an example!
CSS
#image {
-webkit-animation: blink 3s;
-webkit-animation-iteration-count: infinite;
-moz-animation: blink 3s;
-moz-animation-iteration-count: infinite;
-o-animation: blink 3s;
-o-animation-iteration-count: infinite;
}
You should also specify a background-image instead of using content:
Note: If there is no content in your div you need to specify a width and height in order to see the background image. By default, the image will be repeated - using no-repeat will have the image only displayed once. Read more on CSS backgrounds here.
Same example but with a background image.
div#image {
background:url(http://www.google.com/images/srpr/logo3w.png) no-repeat;
height: 95px;
width: 280px;
float:left;
}
You have some errors in your CSS.
Your div have id="image". But you selected div.image instead of div#image
You applied the animation property on img instead on your div.
The proper CSS would be
div#image {
content:url(http://www.google.com/images/srpr/logo3w.png);
float:left;
-webkit-animation: blink 1s;
-webkit-animation-iteration-count: infinite;
-moz-animation: blink 1s;
-moz-animation-iteration-count: infinite;
-o-animation: blink 1s;
-o-animation-iteration-count: infinite;
}
#-webkit-keyframes blink {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#-moz-keyframes blink {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#-o-keyframes blink {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
Here is a DEMO
A part of your css code if for the <blink> element and it works if you change it accordingly.
Take a look at my example on jsfiddle.
please see below:
#-webkit-keyframes myfirst /* Safari and Chrome */
{
0% { height:200px; }
50% {opacity:1}
50% {height:300px; opacity: 0; }
}
I would like to start fading the object away only 50% thorugh the animation. not at the beginning. This currently doesn't do any opacity animation.
Not getting your question quiet well but I assume you want to delay the start of your animation, if it's that so.. than you can use animation-delay property... This will help you in delay your animation by few seconds
Demo (Modified demo of my answer here)
.blink_me {
animation-name: blinker;
animation-duration: 1s;
animation-timing-function: linear;
animation-iteration-count: infinite;
-webkit-animation-name: blinker;
-webkit-animation-duration: 1s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
-moz-animation-delay: 5s;
-webkit-animation-delay: 5s;
animation-delay: 5s;
}
#-moz-keyframes blinker {
0% { opacity: 1.0; }
50% { opacity: 0.0; }
100% { opacity: 1.0; }
}
#-webkit-keyframes blinker {
0% { opacity: 1.0; }
50% { opacity: 0.0; }
100% { opacity: 1.0; }
}
#keyframes blinker {
0% { opacity: 1.0; }
50% { opacity: 0.0; }
100% { opacity: 1.0; }
}
As commented by jCuber, if you want to start animation at 50% than try this
Demo
try this i made some changes in your fiddle it's work and also link of new fiddle
<div class="blink_me"> Blink</div>
.blink_me {
animation-name: blinker;
animation-duration: 5s;
animation-iteration-count: infinite;
-webkit-animation-name: blinker;
-webkit-animation-duration: 5s;
-webkit-animation-iteration-count: infinite;
background:#ff0000;
border:1px solid #00ff00;
}
#-webkit-keyframes blinker {
0% {width:20px; opacity: 0;}
50% {width:20px; opacity: 1; }
100% {width:50px; opacity: 0; }
}
http://jsfiddle.net/umz8t/293/
it looks like you just made a simple mistake the last line should read 100% not 50%. It could actually read anything between 51% to 100%. You also were missing a semi-colon, added it in.
#-webkit-keyframes myfirst /* Safari and Chrome */
{
0% { height:200px; }
50% {opacity:1; }
100% {height:300px; opacity: 0; }
}
Have so far got this
http://codepen.io/tacrossman/pen/GJglH
But what i want is for the cursor blinking animation to be running after each new word (span) is written out.
When I try and do something like
.type:after {
content:"_";
opacity: 0;
animation: cursor 1s infinite;
}
it doesn't have the desired effect. I am thinking that there is a conflict in the animation as i am technically running an animation within something that is already animating.
If you need anything else let me know, thanks a lot
Like this? Pretty sure this is what you were trying to achieve.
Updated Codepen result
span > span {
animation: cursor 1s infinite;
}
I also fixed a few glitches in the animation.. some were overlapping each other.
Are you using Safari or Chrome? I'm using Firefox and I noticed an issue is that you are inconsistent with your prefixes.
Here's new code without the webkit prefixes (add them back if you want, but considering it's not working for you, I'm assuming they're not necessary):
Working JSBIN: http://jsbin.com/ITokiXO/1/edit
.type{
position: absolute;
opacity: 0;
width: 12ch;
overflow: hidden;
animation: words 18s steps(12) infinite 0s;
}
.type:nth-child(2) {
-webkit-animation-delay: 3s;
animation-delay: 3s;
}
.type:nth-child(3) {
-webkit-animation-delay: 6s;
animation-delay: 6s;
}
.type:nth-child(4) {
-webkit-animation-delay: 9s;
animation-delay: 9s;
}
.type:nth-child(5) {
-webkit-animation-delay: 12s;
animation-delay: 12s;
}
.type:nth-child(6) {
-webkit-animation-delay: 15s;
animation-delay: 15s;
}
#keyframes words {
0% { opacity: 0; width:0; }
2% { opacity: 1;}
14% { opacity: 1; width: 12ch;}
15% { opacity: 0; }
}
.cursor:after {
content:" _";
opacity: 0;
animation: cursor 1s infinite;
}
#keyframes cursor {
0% {
opacity: 0;
}
40% {
opacity: 0;
}
50% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
opacity: 0;
}
}
here is a type effect but it uses steps in the animation function:
http://codepen.io/jonathan/pen/lwFzv
#-webkit-keyframes typing {
from { width: 0 }
to { width:14em }
}
#keyframes typing {
from { width: 0 }
to { width:14em }
}
#-webkit-keyframes caret {
from, to { border-color: transparent }
50% { border-color: black }
}
#keyframes caret {
from, to { border-color: transparent }
50% { border-color: black }
}
body { font-family: Consolas; }
h1 {
font-size:150%;
width:14em;
white-space:nowrap;
overflow:hidden;
border-right: .1em solid #333;
-webkit-animation: typing 13s steps(26, end),
caret 0.5s step-end infinite;
animation: typing 13s steps(26, end),
caret 0.5s step-end infinite;
}
you will notice the steps is set to 26 which is the number of characters in my H1
<h1>Typing Effect by Jonathan.</h1>
you could probably use the :after but it might require JS to calculate the word length for each word
also it best to always add the property without the vendor prefixes so it can used in browsers that support the animation property.. like in this case firefox does not need the vendor prefix
http://caniuse.com/#feat=css-animation