Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a loading spinner written in CSS, but I need to add the ability of a fallback animated GIF for browsers that do not support the CSS code. (I have already added some vendor prefixes too) I'm not sure where and how I would add any fallback code and what the code should ideally be. I have supplied a version of the CSS class below. Can anyone help?

Thanks!

----

.loading {
margin: 10% auto;
border-bottom: 11px solid #fff;
border-left: 11px solid #fff;
border-right: 11px solid #fff;
border-top: 11px solid #59AFDA;
border-radius: 100%;
height: 120px;
width: 120px;
-webkit-animation: spin 1.2s infinite linear;
-moz-animation: spin 1.2s infinite linear;
-ms-animation: spin 1.2s infinite linear;
-o-animation: spin 1.2s infinite linear;
animation: spin 1.2s infinite linear;
}

@keyframes "spin" {
from {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
-ms-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
-moz-transform: rotate(359deg);
-o-transform: rotate(359deg);
-ms-transform: rotate(359deg);
transform: rotate(359deg);
}

}

@-moz-keyframes spin {
from {
-moz-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-moz-transform: rotate(359deg);
transform: rotate(359deg);
}

}

@-webkit-keyframes "spin" {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}

}

@-ms-keyframes "spin" {
from {
-ms-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-ms-transform: rotate(359deg);
transform: rotate(359deg);
}

}

@-o-keyframes "spin" {
from {
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-o-transform: rotate(359deg);
transform: rotate(359deg);
}

}
Posted

1 solution

The simplest solution would probably be to add Modernizr[^] to your site with the "CSS Animations" and "Add CSS Classes" options selected. This will add a "cssanimations" class to the HTML element in browsers which support CSS animations, which you can use to adapt your CSS:

CSS
.loading {
    ...
    background-image: url(loading-spinner.gif);
}
.cssanimations .loading {
    background-image: none;
    -webkit-animation: spin 1.2s infinite linear;
    -moz-animation: spin 1.2s infinite linear;
    -ms-animation: spin 1.2s infinite linear;
    -o-animation: spin 1.2s infinite linear;
    animation: spin 1.2s infinite linear;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900