I'm trying to scale, rotate and translate an element using CSS3 animation. This animation works as expected in chrome but i'm unable to reproduce it in Firefox and IE10.
In FF and IE, only the scale transformation works on element when using:
transform: scale(.3) rotate(360deg) translateY(30px) translateX(10px);
Here a jsFiddle which reproduces this issue: DEMO jsFiddle
This is the HTML part:
<div class="preloader">
<i></i>
</div>
CSS part:
.preloader {
width:240px;
height:30px
}
.preloader i {
position:absolute;
top:0;
background-color:transparent;
width:29px;
height:29px;
border: 1px solid #fff;
-webkit-animation: test 1s infinite linear;
-webkit-transform:scale(0);
-ms-animation: test 1s infinite linear;
-ms-transform:scale(0);
animation: test 1s infinite linear;
transform:scale(0);
border-radius:30px 0px 10px 0px;
}
.preloader i {
left:0;
-webkit-animation-delay:0.52s;
-ms-animation-delay:0.52s;
animation-delay:0.52s;
}
#-webkit-keyframes test {
0% {
-webkit-transform:scale(1);
background-color:#A300A3;
}
100% {
-webkit-transform:scale(.3) rotate(360deg) translateY(30px) translateX(10px);
background-color:transparent;
border-color:transparent;
border-radius: 15px;
}
}
#-ms-keyframes test {
0% {
-ms-transform:scale(1);
background-color:#A300A3;
}
100% {
-ms-transform:scale(.3) rotate(360deg) translateY(30px) translateX(10px);
background-color:transparent;
border-radius: 15px;
}
}
#keyframes test {
0% {
transform:scale(1);
background-color:#A300A3;
}
100% {
transform: scale(.3) rotate(360deg) translateY(30px) translateX(10px);
background-color:transparent;
border-radius: 15px;
}
}
IE doesn't need the -ms prefix for the animation property, so remove the #-ms-keyframes and -ms-animation rules.
You have to expand the transform shorthand on both the .preloader i selector and within the #keyframes rule to include the initial values for the properties you're animating: Demo
.preloader i {
-webkit-animation: test 1s infinite linear;
-webkit-transform:scale(0);
animation: test 1s infinite linear;
transform: scale(0) rotate(0deg) translateY(0px) translateX(0px);
}
#keyframes test {
0% {
transform: scale(1) rotate(0deg) translateY(0px) translateX(0px);
background-color:#A300A3;
}
100% {
transform: scale(.3) rotate(360deg) translateY(30px) translateX(10px);
background-color:transparent;
border-radius: 15px;
}
}
Related
In the linked fiddle, an element has two animations.
https://jsfiddle.net/ccqpLa6L/1/
Below is a capture of the CSS:
#-webkit-keyframes slideInLeft { 0% { transform: translateX(-200px); } 100% { transform: translateX(0); } }
#-webkit-keyframes slideOutLeft { 0% { transform: translateX(0); } 100% { transform: translateX(100px); }}
.element {
width: 250px;
height: 75px;
background-color: dimgrey;
right: 0;
margin-bottom: 10px;
border-radius: 5px;
-webkit-animation: slideInLeft 1s forwards, slideOutLeft 2s forwards;
-webkit-animation-delay: 0s, 1s;
}
The first animation executes without an issue, but the second animation jumps to the end of its animation without any interstitial frames.
Why?
While I'm not exactly sure why the animation wasn't running properly, I was able to achieve the desired effect using spaced out percentages in one keyframe:
https://jsfiddle.net/ccqpLa6L/5/
#-webkit-keyframes slideInLeft {
0% {
transform: translateX(-200px);
}
25% {
transform: translateX(0);
}
50% {
transform: translateX(0);
}
100% {
-webkit-transform: translateX(100px);
}
}
.element {
width: 250px;
height: 75px;
background-color: dimgrey;
margin-bottom: 10px;
border-radius: 5px;
-webkit-animation: slideInLeft 4s forwards;
}
I'm trying to get a bouncing mouse animation to work on my website.
The exact same code works on another website, whereas on mine it just doesn't do anything.
Here's the css:
.mouse {
display: block;
margin: 0 auto;
text-align: center;
width: 100%;
font-size: 32px;
color: #fff;
z-index:9999;
position: absolute;
color: #e8e8e8;;
bottom: 240px;
}
.mouse i {
-webkit-animation: todown 1.2s infinite linear;
transition: all 0.3s ease-in-out;
}
The HTML:
<a href="#x11" class="mouse">
<i class="fa fa-angle-double-down icon-option"></i>
</a>
On this website you can see the scrolldown icon I'm trying to create: http://noxxar.com/demo/uralco/
If you want to use CSS animations you need to define #keyframes.
Luckily the CSS on the theme you linked isn't minified or anything, so you can just copy/paste the parts you want to recreate.
Since Firefox 15 the -moz vendor prefix isn't needed but Chrome and other Webkit Browser still need -webkit-animation: http://caniuse.com/#feat=css-animation
CSS:
#to-slider-scrollto i {
-webkit-animation: todown 1.2s infinite linear;
animation: todown 1.2s infinite linear;
}
#to-slider-scrollto i:hover {
-webkit-animation: none;
animation: none;
}
#-webkit-keyframes todown {
0% {
-webkit-transform: translateY(-15px);
opacity: 0;
}
10% {
-webkit-transform: translateY(-15px);
opacity: 0;
}
50% {
-webkit-transform: translateY(0);
opacity: 1;
}
90% {
-webkit-transform: translateY(15px);
opacity: 0;
}
100% {
-webkit-transform: translateY(15px);
opacity: 0;
}
}
#keyframes todown {
0% {
transform: translateY(-15px);
opacity: 0;
}
10% {
transform: translateY(-15px);
opacity: 0;
}
50% {
transform: translateY(0);
opacity: 1;
}
90% {
transform: translateY(15px);
opacity: 0;
}
100% {
transform: translateY(15px);
opacity: 0;
}
}
Working codepen demo with only the needed CSS
Check out cross browser compatibility
.mouse i {
-webkit-animation: todown 1.2s linear infinite;
animation: todown 1.2s linear infinite;
}
#-webkit-keyframes todown {
0% {
-webkit-transform: translateY(0px);
transform: translateY(0px);
}
50% {
-webkit-transform: translateY(5px);
transform: translateY(5px);
}
}
#keyframes todown {
0% {
-webkit-transform: translateY(0px);
transform: translateY(0px);
}
50% {
-webkit-transform: translateY(5px);
transform: translateY(5px);
}
}
Im trying to make a snake loader spinner with css using keyframes animation but i don't know it doesn't work
someone can help?
here the fiddle:
https://jsfiddle.net/fs6kafsn/
#keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.spinner {
display: block;
margin: 50px;
height: 28px;
width: 28px;
animation: rotate 0.8s infinitelinear!important;
-webkit-animation: rotate 0.8s infinitelinear!important;
border: 8px solid red;
border-right-color: transparent;
border-radius: 50%;
position:relative;
}
thanks in advance
You need to add prefixing to your keyframes as well.
fiddle demo
#-webkit-keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
This would need to be prefixed with -moz- as well for firefox compatibility.
Note
the unprefixed version should always be placed after the prefixed versions.
Full Demo
.spinner {
display: block;
margin: 50px;
height: 28px;
width: 28px;
-webkit-animation: rotate 0.8s infinite linear !important;
-moz-animation: rotate 0.8s infinite linear !important;
animation: rotate 0.8s infinite linear !important;
border: 8px solid red;
border-right-color: transparent;
border-radius: 50%;
position:relative;
}
#-webkit-keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#-moz-keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<div class="spinner">
</div>
For webkit based browser like chrome you need #-webkit-keyframes and for Mozilla firefox you need #-moz-keyframes
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#-webkit-keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#-moz-keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.spinner {
display: block;
margin: 50px;
height: 28px;
width: 28px;
animation: spin 0.8s infinite linear!important;
-webkit-animation: spin 0.8s infinite linear!important;
border: 8px solid red;
border-right-color: transparent;
border-radius: 50%;
position:relative;
}
<div class="spinner">
</div>
I changed your fiddle. Here is the working animation: fiddle:
Code:
#-moz-keyframes myanimation /* Firefox */
{
0% {transform: rotate(0deg);}
100% {transform: rotate(360deg);}
}
#-webkit-keyframes myanimation /* Safari and Chrome */
{
0% {transform: rotate(0deg);}
100% {transform: rotate(360deg);}
}
.spinner {
display: block;
margin: 50px;
height: 28px;
width: 28px;
animation:myfirst 5s;
-moz-animation:myanimation 0.8s infinite linear; /* Firefox */
-webkit-animation:myanimation 0.8s infinite linear; /* Safari and Chrome */
border: 8px solid red;
border-right-color: transparent;
border-radius: 50%;
position:relative;
}
After hide and show of the parent element, the child element no longer rotates(loses it css3 animation).
Removing parent element animation and doing hide/show won't cause the same issue(The issue only occurs when the parent element also have an animation)
I was testing in IE 11.
Is this a known issue?
Here is the snippet in codepen(copied below) http://codepen.io/agirma/pen/byIEd
/*-------- CSS start ---------*/
#-webkit-keyframes show_content {
from {
-webkit-transform: scale(0);
opacity:0;
transform: scale(0);
opacity:0;
}
to {
-webkit-transform: scale(1);
opacity:1;
transform: scale(1);
opacity:1;
}
}
#keyframes show_content {
from {
-webkit-transform: scale(0);
opacity:0;
transform: scale(0);
opacity:0;
}
to {
-webkit-transform: scale(1);
opacity:1;
transform: scale(1);
opacity:1;
}
}
#-webkit-keyframes rotate_content {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes rotate_content {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#parent {
display:block;
background:gray;
width: 100px;
height: 100px;
padding: 20px;
-webkit-animation: show_content 4s;
-ms-animation: show_content 4s;
amimation: show_content 4s;
}
#child {
display:block;
width:80px;
height: 80px;
border:solid 1px red;
-webkit-animation: rotate_content 1s linear infinite;
-ms-animation: rotate_content 1s linear infinite;
amimation: rotate_content 1s linear infinite;
}
/*------------CSS end----------*/
<div id="parent">
<div id="child"></div>
</div>
<button onclick="toggleVisibility()">toggle display</button>
<script>
function toggleVisibility() {
var div = document.getElementById('parent');
div.style.display = div.style.display == 'none' ? 'block' : 'none';
}
</script>
I don't believe this issue is "known". I found it myself a couple of weeks ago when IE-testing a webapp I'm building. I finally got around to looking at it today, and upon noticing the same conditions for occurrence that you've listed, I decided to submit a bug report for IE. I was just about to do that when I found this question.
My bug report:
https://connect.microsoft.com/IE/feedbackdetail/view/941104/ie-11-bug-with-nested-css-animations-upon-display-of-previously-hidden-parent
Update:
The bug was successfully reproduced by Microsoft engineers and will be investigated.
I am testing some css animation and cant get this elements :before to rotate, any help?
http://jsfiddle.net/gespinha/hZjkp/5/
CSS
.footerLink{
padding:20px;
background:#000;
color:#fff;
}
.footerLink:before{
content:'ABC';
margin-right:15px;
-webkit-animation: footerHoverOff .5s ease both;
-moz-animation: footerHoverOff .5s ease both;
animation: footerHoverOff .5s ease both;
}
.footerLink:hover:before{
-webkit-animation: footerHoverOn .5s ease both;
-moz-animation: footerHoverOn .5s ease both;
animation: footerHoverOn .5s ease both;
}
#-webkit-keyframes footerHoverOn{ to { -webkit-transform: scale(1.5) rotate(360deg); } }
#-moz-keyframes footerHoverOn{ to { -moz-transform: scale(1.5) rotate(360deg); } }
#keyframes footerHoverOn{ to { transform: scale(1.5) rotate(360deg); } }
#-webkit-keyframes footerHoverOff{ from { -webkit-transform: scale(1.5) rotate(360deg); } }
#-moz-keyframes footerHoverOff{ from { -moz-transform: scale(1.5) rotate(360deg); } }
#keyframes footerHoverOff{ from { transform: scale(1.5) rotate(360deg); } }
Dude, this isn't how you go about css keyframe animation. You are confusing the syntax with transtions.
With keyframe animation:
.footerLink{
padding:20px;
background:#000;
color:#fff;
}
.footerLink:before{
content:'ABC';
margin-right:15px;
}
.footerLink:before:hover {
animation: footerHover .5s;
}
#keyframes footerHover {
from { transform: scale(1.5) rotate(0deg); }
to { transform: scale(1.5) rotate(360deg); }
}
With transitions:
.footerLink{
padding:20px;
background:#000;
color:#fff;
}
.footerLink:before{
content:'ABC';
margin-right:15px;
transform: scale(1.5) rotate(0deg);
transition: .5s;
}
.footerLink:before:hover {
transform: scale(1.5) rotate(360deg);
}