Timing for opacity keyframe animation - css

I'm trying to animate the opacity on some simple Font Awesome icons, but I can't get the timing right.
Basically, of the 5 circles, I want the last 3 on either end to animate on together. So, when the far-left 3 are on, the remaining far-right 2 are off and vice versa. I sort of have this happening on the last 2 on either end, but it's not very smooth and I haven't accounted for the middle one yet. I'm reversing the animation on either end, but I'm not sure if I should just create separate keyframes.
Desired pattern: https://youtu.be/zPPhFs1Y4Ts?t=89
#keyframes blinker-skip {
0% {
opacity: 0;
}
10% {
opacity: 0;
}
20% {
opacity: 0;
}
30% {
opacity: 0;
}
40% {
opacity: 0;
}
50% {
opacity: 0;
}
60% {
opacity: 0;
}
70% {
opacity: 1;
}
80% {
opacity: 0;
}
90% {
opacity: 0;
}
100% {
opacity: 0;
}
}
.boosted-led-blink-skip-first {
animation: blinker-skip 1s linear infinite;
}
.boosted-led-blink-skip-second {
animation: blinker-skip 1s linear reverse infinite;
}
.boosted-led-blink-middle {
animation: blinker 1s step-start infinite;
}
.boosted-led-orange {
color: #ff8533;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css">
<div class="boosted-leds">
<span class="boosted-led-orange boosted-led-blink-skip-first boosted-led"><i class="fas fa-circle"></i></span>
<span class="boosted-led-orange boosted-led-blink-skip-first boosted-led"><i class="fas fa-circle"></i></span>
<span class="boosted-led-orange boosted-led-blink-middle boosted-led"><i class="fas fa-circle"></i></span>
<span class="boosted-led-orange boosted-led-blink-skip-second boosted-led"><i class="fas fa-circle"></i></span>
<span class="boosted-led-orange boosted-led-blink-skip-second boosted-led"><i class="fas fa-circle"></i></span>
</div>
Demo: https://codepen.io/ourcore/pen/GRZYjxZ

It looks like you want the dots to show for 50% of the time on one side and then 50% of the time of the other side.
You can do this by having the opacity at 0 from 0-49% and then set it to 1 for 50-100%. You already use reverse for the second set so that will (obviously!) run the opposite way for set 2.
Working example:
.boosted-led-orange {
color: #ff8533;
}
#keyframes blinker-skip {
0% {
opacity: 0;
}
49% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 1;
}
}
.boosted-led-blink-skip-first {
animation: blinker-skip 1s linear infinite;
}
.boosted-led-blink-skip-second {
animation: blinker-skip 1s linear reverse infinite;
}
.boosted-led-blink-middle {
animation: blinker 1s step-start infinite;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css">
<div class="boosted-leds">
<span class="boosted-led-orange boosted-led-blink-skip-first boosted-led"><i class="fas fa-circle"></i></span>
<span class="boosted-led-orange boosted-led-blink-skip-first boosted-led"><i class="fas fa-circle"></i></span>
<span class="boosted-led-orange boosted-led-blink-middle boosted-led"><i class="fas fa-circle"></i></span>
<span class="boosted-led-orange boosted-led-blink-skip-second boosted-led"><i class="fas fa-circle"></i></span>
<span class="boosted-led-orange boosted-led-blink-skip-second boosted-led"><i class="fas fa-circle"></i></span>
</div>
Note that you only need to include the keyframes for the times where the changes occur - there is no need to include the ones in between.

If you are intrested you can do this with one element and without font awesome
.loading {
width:200px;
margin:5px;
background:linear-gradient(#ff8533 0 0) left/60% 100% no-repeat;
-webkit-mask:radial-gradient(circle closest-side, #fff 97%,transparent 100%) 0/calc(100%/5) 100%;
animation: blinker-skip 1s linear infinite;
}
.loading::before {
content:"";
display:block;
padding-top:calc(100%/5 - 5px); /* 5px is the space between circles */
}
#keyframes blinker-skip {
0%,49% {
background-position: left;
}
50%,100% {
background-position: right;
}
}
<div class="loading"></div>
<div class="loading" style="width:150px"></div>
<div class="loading" style="width:120px"></div>

Related

Animate icon sequence and reverse direction in infinite loop

I'm trying to animate icons to show this infinite sequence:
1 2 3 2 1 2 3 2 1 2 3 ...
So 1 2 3, then reverse direction back to 1, then reverse up to 3, etc.
This is what I managed to do:
.fader .icon {
animation-name: fade;
animation-iteration-count: infinite;
animation-duration: 3s;
/*animation-direction: alternate;*/
}
#keyframes fade {
0% { opacity: 1; }
33% { opacity: 0; }
66% { opacity: 0; }
100% { opacity: 1; }
}
#icon3 { animation-delay: 0s; }
#icon2 { animation-delay: -1s; }
#icon1 { animation-delay: -2s; }
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.10.2/font/bootstrap-icons.css" />
<div class="fader mt-3 ms-3">
<div class="position-relative">
<span id="icon3" class="icon bi bi-3-square fs-1 position-absolute top-0 start-0"></span>
<span id="icon2" class="icon bi bi-2-square fs-1 position-absolute top-0 start-0"></span>
<span id="icon1" class="icon bi bi-1-square fs-1 position-absolute top-0 start-0"></span>
</div>
</div>
Currently it goes one way only, without "reversing" direction. Any idea how to fix it?
We set it in shorthand using 'alternate' 1-2-3-2-1-infinite.
In longhand it is:
animation-name: fade;
animation-duration: 4s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-timing-function: ease-in-out;
.icon {
position-relative;
animation: fade 4s infinite alternate ease-in-out;
}
#keyframes fade {
0% { opacity: 1; }
25% { opacity: 0; }
50% { opacity: 0; }
75% { opacity: 0; }
100% { opacity: 1; }
}
#icon1 { animation-delay: 0s; }
#icon2 { animation-delay: -1s; }
#icon3 { animation-delay: -2s; }
#icon4 { animation-delay: -3s; }
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.10.2/font/bootstrap-icons.css" rel="stylesheet"/>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="fader mt-3 ms-3">
<div>
<span id="icon1" class="icon bi bi-1-square fs-1 position-absolute top-0 start-0"></span>
<span id="icon2" class="icon bi bi-2-square fs-1 position-absolute top-0 start-0"></span>
<span id="icon3" class="icon bi bi-3-square fs-1 position-absolute top-0 start-0"></span>
<span id="icon4" class="icon bi bi-2-square fs-1 position-absolute top-0 start-0"></span>
</div>
</div>

Add css for class

I have original CSS from example
CSS:
a.blink, a:hover.blink {
color: white;
}
span.blink {
animation: blinker 1s linear infinite;
}
#keyframes blinker {
50% { opacity: 0; }
}
<span style="background-color: red" class="blink">
<a href="./?np&id={$i->id}" target="_blank" class="blink">
#{$i->id}
</a>
</span>
How i can use this style for "records" class?
<div class="records">
<a class="blink" href="index.php?id=494172" target="_blank">#494172</a>
</div>
And my test CSS
div.records a.blink, div.records a.hover.blink {
color: white;
}
You should add this to your CSS:
.records .blink,
.records .hover.blink {
color: white;
}
.blink {
animation: blinker 1s linear infinite;
}
#keyframes blinker {
50% {
opacity: 1;
background-color: red;
}
}
This is how it looks like on jsfiddle: https://jsfiddle.net/um9a0L7d/1/
Please add this to css
div.records { animation: blinker 1s linear infinite; background-color: red; }

Animate between fontawesome icons not working in IE

I've created an animation to cycle through a set of individual FontAwesome icons. It is working on latest Firefox and Chrome, but on IE (10, 11, Edge) the icon simply doesn't change.
To prove that IE is at least trying to animate, I've added the colour CSS.
Is this something that just can't be done on IE with CSS alone?
i::before {
animation: battery 5s infinite;
font-size:2em;
}
#keyframes battery {
0% { content: "\f244"; color:red; }
25% { content: "\f243"; color:green; }
50% { content: "\f242"; color:blue; }
75% { content: "\f241"; color:yellow; }
100% { content: "\f240"; color:purple; }
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" crossorigin="anonymous">
<i class="fas fa-battery-empty"></i>
As I commented, you can try with stacking icons:
i.fas {
animation: battery 5s infinite;
opacity:0;
color:red;
}
i.fas:nth-child(2) {animation-delay:1s;}
i.fas:nth-child(3) {animation-delay:2s;}
i.fas:nth-child(4) {animation-delay:3s;}
i.fas:nth-child(5) {animation-delay:4s;}
#keyframes battery{
0%,20% { /* 20 = 100 / 5 */
opacity:1;
}
21%,100% {
opacity:0;
}
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" crossorigin="anonymous">
<span class="fa-stack fa-4x">
<i class="fas fa-stack-1x fa-battery-empty"></i>
<i class="fas fa-stack-1x fa-battery-quarter"></i>
<i class="fas fa-stack-1x fa-battery-half"></i>
<i class="fas fa-stack-1x fa-battery-three-quarters"></i>
<i class="fas fa-stack-1x fa-battery-full"></i>
</span>
For IE, you may look instead at text-indent and move the icon steps by steps instead updating the content value.
i::after {
animation: battery 10s infinite;
display: inline-block;
width: 0;
text-indent: -1.25em;
content: " \f244 \f243 \f242 \f241 \f240";
white-space: nowrap;
position:relative;
z-index:-1;
}
i {
overflow: hidden;
font-size: 2em;
}
#keyframes battery {/* update values and steps to your needs */
0% {
text-indent: -1.25em;
color: green;
}
19.9999% {
text-indent: -1.25em;
}
20% {
text-indent: -2.75em;
color: green;
}
39.999% {
text-indent: -2.75em;
}
40% {
text-indent: -4em;
}
59.999% {
text-indent: -4em;
color: blue;
}
60% {
text-indent: -5.25em;
}
79.999% {
text-indent:-5.25em;
color: orange;
}
80% , 100%{
text-indent: -6.5em;
color: red;
}
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" crossorigin="anonymous">
<i class="fas fa-battery-empty"></i>
If you're using the SVG sprites with the JS version of font-awesome then the CSS is slightly different.
The font-awesome JS removes the fas class and turns it into a data-prefix property so you'll have to add an identifier to the <span>
.battery svg {
animation: battery 5s infinite;
opacity: 0;
color: red;
}
.battery svg:nth-child(2) {
animation-delay: 1s;
}
.battery svg:nth-child(3) {
animation-delay: 2s;
}
.battery svg:nth-child(4) {
animation-delay: 3s;
}
.battery svg:nth-child(5) {
animation-delay: 4s;
}
#keyframes battery {
0%, 20% { /* 20 = 100 / 5 */
opacity: 1;
}
21%, 100% {
opacity: 0;
}
}
...
<script src="https://pro.fontawesome.com/releases/v5.13.0/js/all.js" crossorigin="anonymous"></script>
<span class="fa-stack fa-4x battery">
<i class="fas fa-stack-1x fa-battery-empty"></i>
<i class="fas fa-stack-1x fa-battery-quarter"></i>
<i class="fas fa-stack-1x fa-battery-half"></i>
<i class="fas fa-stack-1x fa-battery-three-quarters"></i>
<i class="fas fa-stack-1x fa-battery-full"></i>
</span>

Spin animation initiated on hover but still completes when off hover

So I have completed some simple code to spin the inside element when you hover on the container.
This works just as I want it when the mouse is hovering over the container but when the mouse is no longer within the container the spin stops.
How can I complete a full spin rotation, initiated by a mouse hover where it will complete a full spin even if the mouse leaves the container, preferably with just CSS.
Current code:
HTML
#keyframes spin {
0% { transform: rotate(0deg); }
25% { transform: rotate(-90deg); }
50%{ transform: rotate(-180deg); }
75% { transform: rotate(-270deg); }
100% { transform: rotate(-360deg); }
}
.logo:hover > .spin{
animation: spin 450ms;
}
.logo{
background: #eee;
width: 100px;
height: 100px;
text-align: center;
line-height: 110px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<a href="#">
<div class="logo">
<i class="fa fa-globe fa-2x spin" aria-hidden="true"></i>
</div>
</a>
This should work ! :)
jQuery(document).ready(function(){
jQuery(".logo").hover(function(){
var logo = jQuery(this);
if(!logo.hasClass('hover')){
logo.addClass('hover');
setTimeout(function(){
logo.removeClass('hover');
}, 450);
}
}, function(){});
});
#keyframes spin {
0% { transform: rotate(0deg); }
25% { transform: rotate(-90deg); }
50%{ transform: rotate(-180deg); }
75% { transform: rotate(-270deg); }
100% { transform: rotate(-360deg); }
}
.logo.hover > .spin{
animation: spin 450ms;
}
.logo{
background: #eee;
width: 100px;
height: 100px;
text-align: center;
li
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<a href="#">
<div class="logo">
<i class="fa fa-globe fa-2x spin" aria-hidden="true"></i>
</div>
</a>

CSS animations, slide in on 'block' and out on 'none'

I'm building something that is using the css slide animation to have some text slide in when the text display is set to "block", but I was wondering how I would go about doing the reverse (sliding it out) when it is set to "none"? Is it possible to slide in and slide out with CSS animations, or would I have to use Javascript?
Hope that makes sense! Let me know if you have any questions!
JSfiddle of give you a better idea https://jsfiddle.net/qjwqL236/
Thanks!
And code below:
document.getElementById("in-button").onclick = function(){
document.getElementById("text-container").style.display = "block";
}
document.getElementById("out-button").onclick = function(){
document.getElementById("text-container").style.display = "none";
}
#text-container{
height: 30px;
width:300px;
color: white;
background-color: blue;
float:left;
display:none;
position: relative;
left: -300px;
animation: slide 0.5sforwards;
-webkit-animation: slide 0.5s forwards;
}
#-webkit-keyframes slide {
100% {
left: 0;
}
}
#keyframes slide {
100% {
left: 0;
}
}
#in-button{
float:left;
}
#out-button{
float:left;
}
<button id="in-button">
Make Div slide in
</button>
<button id="out-button">
Make Div slide out?
</button>
<br>
<br>
<div id="text-container">
This is some text in a div.
</div>
In your case. It's easier to use transition than animation. This is how it works.
Everytime the button is click. It changes the value of the left property.
<button id="in-button">
Make Div slide in
</button>
<button id="out-button">
Make Div slide out?
</button>
<br>
<br>
<div id="text-container">
This is some text in a div.
</div>
CSS
#text-container{
height: 30px;
width:300px;
color: white;
background-color: blue;
float:left;
position: relative;
left: -400px;
transition: all 0.3s linear
}
#in-button, #out-button{
float:left;
}
JS
var tC = document.getElementById('text-container');
document.getElementById("in-button").onclick = function(){
tC.style.left = '0';
}
document.getElementById("out-button").onclick = function(){
tC.style.left = '-400px';
}
Working fiddle: https://jsfiddle.net/qjwqL236/1/
You should use css translate because it's more performant than positioning and then you need an animation in and an animation out that you can trigger with a class change instead of the display property.
document.getElementById("in-button").onclick = function(){
document.getElementById("text-container").className = "in";
}
document.getElementById("out-button").onclick = function(){
document.getElementById("text-container").className = "out";
}
#text-container{
height: 30px;
width: 300px;
color: white;
background-color: blue;
transform: translateX(-310px);
}
#text-container.in {
animation: in 0.5s both;
-webkit-animation: in 0.5s both;
}
#text-container.out {
animation: out 0.5s both;
-webkit-animation: out 0.5s both;
}
#-webkit-keyframes in {
100% {
transform: translateX(0);
}
}
#keyframes in {
100% {
transform: translateX(0);
}
}
#-webkit-keyframes out {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-310px);
}
}
#keyframes out {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-310px);
}
}
#in-button{
float:left;
}
#out-button{
float:left;
}
<button id="in-button">
Make Div slide in
</button>
<button id="out-button">
Make Div slide out?
</button>
<br>
<br>
<div id="text-container">
This is some text in a div.
</div>
Here is what you can do using animations. You need to create a slide-out animation just like you have a slide-in.
Note that it won't slide in/out automatically when you change the display to none or block.
document.getElementById("in-button").onclick = function() {
document.getElementById("text-container").setAttribute('class', 'slide-in');
}
document.getElementById("out-button").onclick = function() {
document.getElementById("text-container").setAttribute('class', 'slide-out');
}
#text-container {
height: 30px;
width: 300px;
color: white;
background-color: blue;
float: left;
position: relative;
left: -300px;
}
.slide-in {
animation: slide-in 0.5s forwards;
-webkit-animation: slide-in 0.5s forwards;
}
.slide-out {
animation: slide-out 0.5s forwards;
-webkit-animation: slide-out 0.5s forwards;
}
#-webkit-keyframes slide-in {
100% {
left: 0;
}
}
#keyframes slide-in {
100% {
left: 0;
}
}
#-webkit-keyframes slide-out {
0% {
left: 0;
}
100% {
left: -300px;
}
}
#keyframes slide-out {
0% {
left: 0;
}
100% {
left: -300px;
}
}
#in-button {
float: left;
}
#out-button {
float: left;
}
<button id="in-button">
Make Div slide in
</button>
<button id="out-button">
Make Div slide out?
</button>
<br>
<br>
<div id="text-container">
This is some text in a div.
</div>

Resources