I am trying to get an image to slide out to the left when the page loads using purely CSS.
So, far I've got: http://jsfiddle.net/o7thwd/qZbhJ/ and it seems to work. The issue I can't seem to get over is how the image comes back into view once the animation is over.
#slide {
left:0;
width:268px;
-moz-animation-name: slideOut;
-moz-animation-iteration-count: once;
-moz-animation-timing-function: ease-out;
-moz-animation-duration: 1.5s;
-webkit-animation-name: slideOut;
-webkit-animation-iteration-count: once;
-webkit-animation-timing-function: ease-out;
-webkit-animation-duration: 1.5s;
-o-animation-name: slideOut;
-o-animation-iteration-count: once;
-o-animation-timing-function: ease-out;
-o-animation-duration: 1.5s;
animation-name: slideOut;
animation-iteration-count: once;
animation-timing-function: ease-out;
animation-duration: 1.5s;
}
#-o-keyframes slideOut {
0% {
margin-left: 0;
}
100% {
margin-left: -268px;
}
}
#keyframes slideOut {
0% {
margin-left: 0;
}
100% {
margin-left: -268px;
}
}
#-moz-keyframes slideOut {
0% {
margin-left: 0;
}
100% {
margin-left: -268px;
}
}
#-webkit-keyframes slideOut {
0% {
margin-left: 0;
}
100% {
margin-left: -268px;
}
}
How can I get it to stay folded to the left like it does on initial page load?
basically you add the following CSS -webkit-animation-fill-mode: forwards; and the animation end will be persistent rather than revert back to the original.
WORKING JSFIDDLE
Oh and you only need to use the -webkit- vendor specific for animations there are no -moz- or -o- vendor specifics for animations
CSS:
#slide {
left:0;
width:268px;
-webkit-animation-name: slideOut;
-webkit-animation-iteration-count: once;
-webkit-animation-timing-function: ease-out;
-webkit-animation-duration: 1.5s;
animation-name: slideOut;
animation-iteration-count: once;
animation-timing-function: ease-out;
animation-duration: 1.5s;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
#keyframes slideOut {
0% {
margin-left: 0;
}
100% {
margin-left: -268px;
}
}
#-webkit-keyframes slideOut {
0% {
left: 0;
}
100% {
left: -268px;
}
}
Related
I have a simple CSS animation which runs fine on desktop but doesn't seem to work on iPad. I have tried both Chrome and Safari.
Here's the code:
.scroll-down img {
-webkit-animation: 3s ease 0s normal none infinite running myscroll;
-moz-animation: 3s ease 0s normal none infinite running myscroll;
animation: 3s ease 0s normal none infinite running myscroll;
}
#-webkit-keyframes myscroll {
0% {
opacity: 1
}
50% {
opacity: 1
}
100% {
opacity: 1;
-webkit-transform: translateY(101px);
transform: translateY(101px);
}
}
Do I have some type of syntax error?
always add the generic - not browser specific version of css when also using the browser one ex.
#-webkit-keyframes myscroll {
0% {
opacity: 1
}
50% {
opacity: 1
}
100% {
opacity: 1;
-webkit-transform: translateY(101px);
transform: translateY(101px);
}
}
#keyframes myscroll {
0% {
opacity: 1
}
50% {
opacity: 1
}
100% {
opacity: 1;
-webkit-transform: translateY(101px);
transform: translateY(101px);
}
}
Found a solution. Apparently iPad doesnt like shorthand so I had to do this:
-webkit-animation-name: myscroll;
-webkit-animation-duration: 3s;
-webkit-animation-delay: 0s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: ease;
-webkit-animation-direction: normal;
-webkit-animation-fill-mode: none;
-webkit-animation-play-state: running;
animation-name: myscroll;
animation-duration: 3s;
animation-delay: 0s;
animation-iteration-count: infinite;
animation-timing-function: ease;
animation-direction: normal;
animation-fill-mode: none;
animation-play-state: running;
I am trying to make this rectangle fade in and then play the second animation? However at the moment it does not fade in and after few seconds just plays the second animation.
Fiddle Demo
HTML CODE:
<div class="rectangle firstAnimation thirdAnimation"></div>
CSS CODE:
#-webkit-keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.fadeIn {
-webkit-animation-name: fadeIn;
animation-name: fadeIn;
}
.rectangle {
position:fixed;
width: 300px;
height: 36px;
opacity:0.8;
margin-top:215px;
background: #212e84;
z-index:1;
}
.firstAnimation {
animation-name: fadeIn;
-webkit-animation-name: fadeIn;
-moz-animation-name: fadeIn;
-webkit-animation-delay: 1s;
animation-delay: 1s;
-moz-animation-delay: 1s;
-webkit-animation-duration: 3s;
-moz-animation-duration: 3s;
animation-duration: 3s;
animation-fill-mode: forwards;
-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
}
#-webkit-keyframes movingbox {
0% {
left:0px;
}
100% {
left:-157px;
}
}
.thirdAnimation {
animation-name: movingbox;
-webkit-animation-name: movingbox;
-moz-animation-name: movingbox;
-webkit-animation-delay: 4s;
animation-delay: 4s;
-moz-animation-delay: 4s;
-webkit-animation-duration: 3s;
animation-duration: 3s;
-moz-animation-duration: 3s;
animation-fill-mode: forwards;
-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
}
You cannot set two different animations under two different selectors in CSS as the latest (or more specific) declaration would overwrite the previous one.
The way to apply more than animation to a single element would be to set comma separated values to the the animation setting like below:
.thirdAnimation {
animation-name: movingbox, fadeIn; /* specify multiple animations in CSV format */
animation-delay: 4s, 0s; /* first value is delay for 1st animation, next is for 2nd */
animation-duration: 3s; /* when only one value is provided, the same applies for both animations */
animation-fill-mode: forwards;
}
Setting animation-delay as 0s for the fadeIn animation would make it start immediately and the animation-duration being 3s means, it would complete before the moving box animation starts (after a 4s delay). You can play around with animation-delay and animation-duration as required.
#keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes movingbox {
0% {
left: 0px;
}
100% {
left: -157px;
}
}
.rectangle {
position: fixed;
width: 300px;
height: 36px;
opacity: 0.8;
margin-top: 15px; /* reduced to make it visible in snippet window */
background: #212e84;
z-index: 1;
}
.thirdAnimation {
animation-name: movingbox, fadeIn;
animation-delay: 4s, 0s;
animation-duration: 3s;
animation-fill-mode: forwards;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class="rectangle thirdAnimation"></div>
Note: In snippet, I have used prefix-free library to avoid all the browser prefixing.
Simillar kind of issue here: CSS Multiple Animations on single element, no javascript
Solution: http://jsfiddle.net/kybernaut/vuzzmoxj/1/
change class only to one, for example "Animation" and than css:
.Animation {
animation-name: fadeIn,movingbox;
-webkit-animation-name: fadeIn,movingbox;
-moz-animation-name: fadeInmovingbox;
-webkit-animation-delay: 3s,4s;
animation-delay: 3s,4s;
-moz-animation-delay: 3s,4s;
-webkit-animation-duration: 3s,3s;
animation-duration: 3s,3s;
-moz-animation-duration: 3s,3s;
animation-fill-mode: forwards;
-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
}
Css animation doesn't work in internet explorer, version 11 for sure.
All the other browsers animate it perfectly good. Here is a website: http://susannahpryce.esy.es
I checked through firebug in IE, it reads the code with no erroers, so i don't know why it doesn't work, i'm using IE 11.
And here is my code
body .main .header-box {
background-color: #fff;
height: 500px;
width: 100%;
float: left; }
body .main .header-box .slide-area {
margin: 0 9%; }
body .main .header-box .slide-area #pic1 {
position: absolute;
z-index: 5;
-webkit-animation-duration: 60s;
-webkit-animation-delay: 10s;
-webkit-transition-timing-function: ease;
-webkit-animation-name: slide-fade;
-webkit-animation-iteration-count: infinite;
-ms-animation-duration: 60s;
-ms-animation-delay: 10s;
-ms-transition-timing-function: ease;
-ms-animation-name: slide-fade;
-ms-animation-iteration-count: infinite;
-moz-animation-duration: 60s;
-moz-animation-delay: 10s;
-moz-transition-timing-function: ease;
-moz-animation-name: slide-fade;
-moz-animation-iteration-count: infinite; }
body .main .header-box .slide-area #pic2 {
position: absolute;
z-index: 4;
-webkit-animation-duration: 60s;
-webkit-animation-delay: 20s;
-webkit-transition-timing-function: ease;
-webkit-animation-name: slide-fade;
-webkit-animation-iteration-count: infinite;
-ms-animation-duration: 60s;
-ms-animation-delay: 20s;
-ms-transition-timing-function: ease;
-ms-animation-name: slide-fade;
-ms-animation-iteration-count: infinite;
-moz-animation-duration: 60s;
-moz-animation-delay: 20s;
-moz-transition-timing-function: ease;
-moz-animation-name: slide-fade;
-moz-animation-iteration-count: infinite; }
body .main .header-box .slide-area #pic3 {
position: absolute;
z-index: 3;
-webkit-animation-duration: 60s;
-webkit-animation-delay: 30s;
-webkit-transition-timing-function: ease;
-webkit-animation-name: slide-fade;
-webkit-animation-iteration-count: infinite;
-ms-animation-duration: 60s;
-ms-animation-delay: 30s;
-ms-transition-timing-function: ease;
-ms-animation-name: slide-fade;
-ms-animation-iteration-count: infinite;
-moz-animation-duration: 60s;
-moz-animation-delay: 30s;
-moz-transition-timing-function: ease;
-moz-animation-name: slide-fade;
-moz-animation-iteration-count: infinite; }
body .main .header-box .slide-area #pic4 {
position: relative;
z-index: 2; }
#-webkit-keyframes slide-fade {
0% {
opacity: 1; }
5% {
opacity: 0; }
50% {
opacity: 0; }
55% {
opacity: 1; }
100% {
opacity: 1; } }
#-ms-keyframes slide-fade {
0% {
opacity: 1; }
5% {
opacity: 0; }
50% {
opacity: 0; }
55% {
opacity: 1; }
100% {
opacity: 1; } }
#-moz-keyframes slide-fade {
0% {
opacity: 1; }
5% {
opacity: 0; }
50% {
opacity: 0; }
55% {
opacity: 1; }
100% {
opacity: 1; } }
Take the animation css out of the media query. I did a simple copy and paste and edited the css a little bit to make it work. As stated here http://caniuse.com/#search=css-animation (thanks to Paulie_D) in the known issues tab
IE10 and IE11 do not support CSS animations inside media queries.
http://jsfiddle.net/xmfj0tk7/
<div class="header-box">
<div class="slide-area">
<img id="pic1" src="http://susannahpryce.esy.es/wp-content/themes/sue/pics/hq-1-optimized.jpg" />
<img id="pic2" src="http://susannahpryce.esy.es/wp-content/themes/sue/pics/hq-2-optimized.jpg" />
<img id="pic3" src="http://susannahpryce.esy.es/wp-content/themes/sue/pics/hq-3-optimized.jpg" />
<img id="pic4" src="http://susannahpryce.esy.es/wp-content/themes/sue/pics/hq-4-optimized.jpg" />
</div>
<div class="slide-area_480">
</div>
<div class="slide-area_640">
</div>
</div>
You should also put the normal css rules in your file, as in without prefixes. Modern browsers should not need the prefixes and in the future, the prefixes should go away at some point... for this animation stuff anyway
historically IE doesn't apply several styles to elements that don't
"have layout."
see: http://www.satzansatz.de/cssd/onhavinglayout.html
Here is a question that was asked regarding opacity in IE.
Hey guys I am currently building an image show (small) with css3 keyframes, and it is working, but only on firefox in some way, and I cant seem to tackle the problem :( It should work in the latest versions of chrome firefox and safari, but its currently only working in firefox.
Anyone can that can help?
Here's the css that should work in al above browsers.
#keyframes cf4FadeInOut {
0% {
opacity:1;
}
17% {
opacity:1;
}
25% {
opacity:0;
}
92% {
opacity:0;
}
100% {
opacity:1;
}
}
.case-image {
position:relative;
height:auto;
width:32%;
}
.case-image img {
position:absolute;
width: 100%;
height: auto;
left:0;
border: 3px solid #f8d206;
-moz-border-radius: 15px;
border-radius: 15px;
margin-left: -3px;
margin-right: -3px;
}
.case-image img {
-webkit-animation-name: cf4FadeInOut;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: 8s;
-moz-animation-name: cf4FadeInOut;
-moz-animation-timing-function: ease-in-out;
-moz-animation-iteration-count: infinite;
-moz-animation-duration: 8s;
-o-animation-name: cf4FadeInOut;
-o-animation-timing-function: ease-in-out;
-o-animation-iteration-count: infinite;
-o-animation-duration: 8s;
animation-name: cf4FadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 8s;
}
.case-image img:nth-of-type(1) {
-webkit-animation-delay: 6s;
-moz-animation-delay: 6s;
-o-animation-delay: 6s;
animation-delay: 6s;
}
.case-image img:nth-of-type(2) {
-webkit-animation-delay: 4s;
-moz-animation-delay: 4s;
-o-animation-delay: 4s;
animation-delay: 4s;
}
.case-image img:nth-of-type(3) {
-webkit-animation-delay: 2s;
-moz-animation-delay: 2s;
-o-animation-delay: 2s;
animation-delay: 2s;
}
.case-image img:nth-of-type(4) {
-webkit-animation-delay: 0;
-moz-animation-delay: 0;
-o-animation-delay: 0;
animation-delay: 0;
}
You need to include the vendor prefixes for the keyframes. See here for an example: http://jsfiddle.net/tjfogarty/Gzxkq/
#keyframes pulse {
0% { width: 40px; height: 40px; }
100% { width: 50px; height: 50px; }
}
#-webkit-keyframes pulse {
0% { width: 40px; height: 40px; }
100% { width: 50px; height: 50px; }
}
#-moz-keyframes pulse {
0% { width: 40px; height: 40px; }
100% { width: 50px; height: 50px; }
}
Etc...
You can also use something like this: http://leaverou.github.com/prefixfree/ to take care of it for you.
I have reviewed quite a few demos and have no idea why I can't get the CSS3 spin to function. I am using the latest stable release of Chrome.
The fiddle:
http://jsfiddle.net/9Ryvs/1/
div {
margin: 20px;
width: 100px;
height: 100px;
background: #f00;
-webkit-animation-name: spin;
-webkit-animation-duration: 40000ms;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: spin;
-moz-animation-duration: 40000ms;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: spin;
-ms-animation-duration: 40000ms;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
-o-transition: rotate(3600deg);
}
<div></div>
To use CSS3 Animation you must also define the actual animation keyframes (which you named spin)
Read https://developer.mozilla.org/en-US/docs/CSS/Tutorials/Using_CSS_animations for more info
Once you've configured the animation's timing, you need to define the appearance of the animation. This is done by establishing two or more keyframes using the #keyframes at-rule. Each keyframe describes how the animated element should render at a given time during the animation sequence.
Demo :
div {
margin: 20px;
width: 100px;
height: 100px;
background: #f00;
-webkit-animation-name: spin;
-webkit-animation-duration: 4000ms;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: spin;
-moz-animation-duration: 4000ms;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: spin;
-ms-animation-duration: 4000ms;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
animation-name: spin;
animation-duration: 4000ms;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
#-ms-keyframes spin {
from { -ms-transform: rotate(0deg); }
to { -ms-transform: rotate(360deg); }
}
#-moz-keyframes spin {
from { -moz-transform: rotate(0deg); }
to { -moz-transform: rotate(360deg); }
}
#-webkit-keyframes spin {
from { -webkit-transform: rotate(0deg); }
to { -webkit-transform: rotate(360deg); }
}
#keyframes spin {
from {
transform:rotate(0deg);
}
to {
transform:rotate(360deg);
}
}
<div></div>
#-moz-keyframes spin {
from { -moz-transform: rotate(0deg); }
to { -moz-transform: rotate(360deg); }
}
#-webkit-keyframes spin {
from { -webkit-transform: rotate(0deg); }
to { -webkit-transform: rotate(360deg); }
}
#keyframes spin {
from {transform:rotate(0deg);}
to {transform:rotate(360deg);}
}
You haven't specified any keyframes. I made it work here.
div {
margin: 20px;
width: 100px;
height: 100px;
background: #f00;
-webkit-animation: spin 4s infinite linear;
}
#-webkit-keyframes spin {
0% {-webkit-transform: rotate(0deg);}
100% {-webkit-transform: rotate(360deg);}
}
You can actually do lots of really cool stuff with this. Here is one I made earlier.
:)
N.B. You can skip having to write out all the prefixes if you use -prefix-free.
As of latest Chrome/FF and on IE11 there's no need for -ms/-moz/-webkit prefix.
Here's a shorter code (based on previous answers):
div {
margin: 20px;
width: 100px;
height: 100px;
background: #f00;
/* The animation part: */
animation-name: spin;
animation-duration: 4000ms;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
#keyframes spin {
from {transform:rotate(0deg);}
to {transform:rotate(360deg);}
}
Live Demo: http://jsfiddle.net/9Ryvs/3057/
HTML with font-awesome glyphicon.
<span class="fa fa-spinner spin"></span>
CSS
#-moz-keyframes spin {
to { -moz-transform: rotate(360deg); }
}
#-webkit-keyframes spin {
to { -webkit-transform: rotate(360deg); }
}
#keyframes spin {
to {transform:rotate(360deg);}
}
.spin {
animation: spin 1000ms linear infinite;
}
The only answer which gives the correct 359deg:
#keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(359deg); }
}
&.active {
animation: spin 1s linear infinite;
}
Here's a useful gradient so you can prove it is spinning (if its a circle):
background: linear-gradient(to bottom, #000000 0%,#ffffff 100%);
To rotate, you can use key frames and a transform.
div {
margin: 20px;
width: 100px;
height: 100px;
background: #f00;
-webkit-animation-name: spin;
-webkit-animation-duration: 40000ms;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: spin;
-moz-animation-duration: 40000ms;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: spin;
-ms-animation-duration: 40000ms;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
}
#-webkit-keyframes spin {
from {
-webkit-transform:rotate(0deg);
}
to {
-webkit-transform:rotate(360deg);
}
}
Example
For the sake of completion, here's a Sass / Compass example which really shortens the code, the compiled CSS will include the necessary prefixes etc.
div
margin: 20px
width: 100px
height: 100px
background: #f00
+animation(spin 40000ms infinite linear)
+keyframes(spin)
from
+transform(rotate(0deg))
to
+transform(rotate(360deg))
#keyframes spin {
from {transform:rotate(0deg);}
to {transform:rotate(360deg);}
}
this will make you to answer the question
For the guys who still search some cool and easy spinner, we have multiple exemples of spinner on fontawesome site : https://fontawesome.com/v4.7.0/examples/
You just have to inspect the spinner you want with your debugger and copy the css styles.