CSS Transform not working properly on Firefox - css

I have this little animation but it does not behave properly on Firefox and it does not work at all on Explorer.
The idea is that when you hover on the gray DIV, the red DIV will animate.
On Firefox it runs only once when you reload the page and the cursor is hover on the gray area. If you want to make it work again it'll not animate. On chrome it works fine.
Oh, before I forget, the animation basics is from animate.css
http://jsfiddle.net/soporo123/8PDnA/5/
The HTML:
<div id="box">
<div id="button" class="bounceIn"></div>
</div>
The CSS:
#box {
width:400px;
height: 400px;
background-color:#999;
}
#button{
width:40px;
height:40px;
background-color:#F00;
}
#box:hover #button{
-webkit-animation-duration:1s;
-moz-animation-duration: 1s;
-ms-animation-duration:1s;
-o-animation-duration:1s;
animation-duration:1s;
}
#-webkit-keyframes bounceIn {
0% {-webkit-transform: scale(.3);}
50% {-webkit-transform: scale(1.05);}
70% {-webkit-transform: scale(.9);}
100% {-webkit-transform: scale(1);}
}
#-moz-keyframes bounceIn {
0% {-moz-transform: scale(.3);}
50% {-moz-transform: scale(1.05);}
70% {-moz-transform: scale(.9);}
100% {-moz-transform: scale(1);}
}
#-o-keyframes bounceIn {
0% {-o-transform: scale(.3);}
50% {-o-transform: scale(1.05);}
70% {-o-transform: scale(.9);}
100% {-o-transform: scale(1);}
}
#keyframes bounceIn {
0% {transform: scale(.3);}
50% {transform: scale(1.05);}
70% {transform: scale(.9);}
100% {transform: scale(1);}
}
.bounceIn {
-webkit-animation-name: bounceIn;
-moz-animation-name: bounceIn;
-o-animation-name: bounceIn;
animation-name: bounceIn;
}
Thanks in advance!!

There are no specific keyframes for moz, opera.
only use #-webkit-keyframes, same counts for animation-name.
Also do all in your hover, also the animation name.
CSS:
#box {
width:400px;
height: 400px;
background-color:#999;
}
#button{
width:40px;
height:40px;
background-color:#F00;
}
#box:hover #button{
-webkit-animation-duration:1s;
animation-duration:1s;
-webkit-animation-name: bounceIn;
animation-name: bounceIn;
}
#-webkit-keyframes bounceIn {
0% {-webkit-transform: scale(.3);}
50% {-webkit-transform: scale(1.05);}
70% {-webkit-transform: scale(.9);}
100% {-webkit-transform: scale(1);}
}
#keyframes bounceIn {
0% {-moz-transform: scale(.3); -o-transform: scale(.3); transform: scale(.3);}
50% {-moz-transform: scale(1.05); -o-transform: scale(1.05); transform: scale(1.05);}
70% {-moz-transform: scale(.9); -o-transform: scale(.9); transform: scale(.9);}
100% {-moz-transform: scale(1); -o-transform: scale(1); transform: scale(1);}
}
here your updated fiddle:
http://jsfiddle.net/8PDnA/10/
I didn't check if -o-transform exists, but just check it at w3c.

Related

CSS transform origin not centered correctly

I have the following snippet of CSS:
#-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg);}
100% { -webkit-transform: rotate(360deg);}
}
#-moz-keyframes spin {
0% { -moz-transform: rotate(0deg);}
100% { -moz-transform: rotate(360deg);}
}
#-o-keyframes spin {
0% { -o-transform: rotate(0deg);}
100% { -o-transform: rotate(360deg);}
}
#-ms-keyframes spin {
0% { -ms-transform: rotate(0deg);}
100% { -ms-transform: rotate(360deg);}
}
#-keyframes spin {
0% { transform: rotate(0deg);}
100% { transform: rotate(360deg);}
}
header .spinner {
position: absolute;
width: 100%;
text-align: center;
margin: 0 auto;
left: 0;
-webkit-animation:spin 1s ease-out .5s;
-moz-animation:spin 1s ease-out .5s;
animation:spin 1s ease-out .5s;
transform-origin: 50%;
}
the animation runs fine, however the origin is slightly wrong making it look like the img is jumping when rotating.

How to correctly do this css3 animation?

I have to animate a skip lorry. Trying to make the skip to move on the lorry but it does not happening correctly in the way it is to be.
The live preview is here. If you'll check it out then you'll understand what I'm saying and trying to do.
I'm making changes in skew() and rotate() but it turns out to be a bad job.
index.html
<!DOCTYPE html>
<html>
<title>Animate Lorry</title>
<head>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div>
<img class="sc" src="img/chain puller.png"/>
</div>
<div>
<img class="animate" src="img/skip lorry.png"/>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</body>
</html>
style.css
body{
background-color: #000;
}
/*LORRY*/
.animate {
padding: 100px;
padding-left:400px;
width: 400px;
height: 180px;
position: relative;
/*-webkit-animation-name: lorry;
-webkit-animation-duration: 15s;
-webkit-animation-fill-mode: forwards;
animation-name: lorry;
animation-duration: 15s;
animation-fill-mode:forwards;*/
}
/* Chrome, Safari, Opera */
/*#-webkit-keyframes lorry {
0% {right:0px; top:0px;}
25% {right:500px; top:0px;}
50% {right:500px; top:0px;}
75% {right:500px; top:0px;}
100% {right:500px; top:0px;}
}
*/
/*#keyframes lorry {
0% {right:0px; top:0px;}
25% {right:500px; top:0px;}
50% {right:500px; top:0px;}
75% {right:500px; top:0px;}
100% {right:500px; top:0px;}
}*/
/*SKIPHIRE*/
.contain {
padding: 250px;
padding-left: 445px;
width: 300px;
height: 160px;
position: absolute;
-webkit-animation-name: container;
-webkit-animation-duration: 5s;
-webkit-animation-delay: 2s;
-webkit-animation-fill-mode: forwards;
animation-name: container;
animation-duration: 5s;
animation-delay:2s;
animation-fill-mode:forwards;
}
#-webkit-keyframes container {
0% {left:0px; bottom:0px;}
25% {left:200px; bottom:0px;}
50% {left:200px; bottom:200px;}
75% {left:0px; bottom:200px;}
100% {left:0px; bottom:150px;}
}
#keyframes container {
0% {left:0px; bottom:0px;}
25% {left:200px; bottom:0px;}
50% {left:200px; bottom:200px;}
75% {left:0px; bottom:200px;}
100% {left:0px; bottom:200px;}
}
.sc {
width: 400px;
height: 300px;
padding: 70px;
float: left;
padding-left: 603px;
position :absolute;
-webkit-animation-fill-mode: forwards;
-webkit-animation: cssAnimation 5s 1 ease;
-moz-animation: cssAnimation 5s 1 ease;
-o-animation: cssAnimation 5s 1 ease;
animation-fill-mode:forwards;
}
#-webkit-keyframes cssAnimation
{
from { -webkit-transform: rotate(0deg) scale(1) skew(1deg) translate(0px); }
to { -webkit-transform: rotate(-15deg) scale(1) skew(-10deg) translate(-150px); }
}
#keyframes cssAnimation
{
from { -webkit-transform: rotate(0deg) scale(1) skew(1deg) translate(0px); }
to { -webkit-transform: rotate(-10deg) scale(1) skew(1deg) translate(-150px); }
}
Tested in chrome only. But should be compatible for IE and Mozilla.
#-webkit-keyframes cssAnimation
{
from { -webkit-transform: rotate(0deg) scale(1) skew(1deg) translate(0px); }
to { -webkit-transform: rotate(-15deg) scale(1) skew(-10deg) translate(-150px); }
from { -moz-transform: rotate(0deg) scale(1) skew(1deg) translate(0px); }
to { -moz-transform: rotate(-15deg) scale(1) skew(-10deg) translate(-150px); }
}
#keyframes cssAnimation
{
from { -webkit-transform: rotate(0deg) scale(1) skew(1deg) translate(0px); }
to { -webkit-transform: rotate(-10deg) scale(1) skew(1deg) translate(-150px); }
from { -moz-transform: rotate(0deg) scale(1) skew(1deg) translate(0px); }
to { -moz-transform: rotate(-10deg) scale(1) skew(1deg) translate(-150px); }
}
Try this
-moz- = mozzila
-ms- = Internet explorer
http://www.w3schools.com/cssref/css3_browsersupport.asp
scroll at the bottom of the page
EDIT:
I actually misread your question thought you didnt manage to make it work on IE and mozzila

Firefox CSS Animation Smoothing (sub-pixel smoothing)

I'm creating a CSS keyframe animation to have an element appear as if it is casually/slowly floating around a bit. It's nested in parents, one which uses translateX() to slowly move it left and right, and one which uses translateY() to slowly and independently move it up and down.
Chrome and Safari render this perfectly, giving it a gradual swaying movement. It smooths the animation (perhaps using sub-pixel smoothing?) so that everything appears very smooth. Firefox however, animates it pixel by pixel, so rather than smoothly swaying about, you can see it jump at every pixel.
View the JSFiddle in Chrome and FireFox to view the difference: http://jsfiddle.net/gonygdfz/6/
Is there any way to make FireFox render this smoothly rather than having it jumping pixel by pixel? It's extremely noticeable in the actual application for this.
The Markup:
<div id="parent">
<div id="move-x">
<div id="move-y">
<div id="child"></div>
</div>
</div>
</div>
The CSS:
#parent {
width: 400px;
height: 326px;
background-color: yellow;
background: url(http://paint.net.amihotornot.com.au/Features/Effects/Plugins/Render/Grid_CheckerBoard_Maker/Grid_CheckerBoard_Maker.Paint.NET.001.png) top center repeat;
}
#child {
position: absolute;
top: 75px;
left: 150px;
width: 100px;
height: 100px;
background-color: black;
animation: range-y 10s infinite ease;
}
#move-x {
animation: range-x 10s infinite ease;
-webkit-animation: range-x 10s infinite ease;
}
#move-y {
animation: range-y 15s infinite ease;
-webkit-animation: range-y 15s infinite ease;
}
#keyframes range-x {
0% {
transform: translateX(0);
}
30% {
transform: translateX(-8px);
}
50% {
transform: translateX(1px);
}
65% {
transform: translateX(6px);
}
80% {
transform: translateX(0px);
}
89% {
transform: translateX(-3px);
}
100% {
transform: translateX(0);
}
}
#keyframes range-y {
0% {
transform: translateY(0);
}
20% {
transform: translateY(13px);
}
35% {
transform: translateY(-1px);
}
70% {
transform: translateY(-14px);
}
90% {
transform: translateY(2px);
}
100% {
transform: translateY(0);
}
}
#-webkit-keyframes range-x {
0% {
transform: translateX(0);
}
30% {
transform: translateX(-8px);
}
50% {
transform: translateX(1px);
}
65% {
transform: translateX(6px);
}
80% {
transform: translateX(0px);
}
89% {
transform: translateX(-3px);
}
100% {
transform: translateX(0);
}
}
#-webkit-keyframes range-y {
0% {
transform: translateY(0);
}
20% {
transform: translateY(13px);
}
35% {
transform: translateY(-1px);
}
70% {
transform: translateY(-14px);
}
90% {
transform: translateY(2px);
}
100% {
transform: translateY(0);
}
}
The rendering engines for each browser is obviously different. Firefox does not implement an anti-aliasing effect on CSS animations. This does not inherently make it better or worse, it just depends on what you are animating. Linear transitions can appear undesirably blurred in Chrome for example.
It appears what you would like to achieve is to have an anti-aliased/sub-pixel smoothed transitions. We can't change the way the engine renders but we can manipulate the animation to appear softer to the end user.
ALL IS NOT LOST
I have modified your answer and rendered a smoother version next to your original. This should appear softer when viewed in Firefox.
CLICK FOR COMPARISON
Techniques used for this effect:
Linear transitions instead of ease.
Box-shadow on animated object. (Softened edge helps create fake AA effect).
Rotate object. Adding the smallest rotate helps to better utilised the rendering engine.
CSS
#parent {
width: 50%;
float:left;
height: 326px;
background-color: yellow;
background: url(http://paint.net.amihotornot.com.au/Features/Effects/Plugins/Render/Grid_CheckerBoard_Maker/Grid_CheckerBoard_Maker.Paint.NET.001.png) top center repeat;
}
#child {
position: absolute;
top: 75px;
left: 150px;
width: 100px;
height: 100px;
background-color: black;
box-shadow:0 0 1px rgba(0,0,0,0.7);
animation: range-y 10s infinite linear;
-webkit-animation: range-y 10s infinite linear;
}
#move-x {
animation: range-x 10s infinite linear;
-webkit-animation: range-x 10s infinite linear;
}
#move-y {
animation: range-y 15s infinite linear;
-webkit-animation: range-y 15s infinite linear;
}
#keyframes range-x {
0% {transform: translateX(0);}
30% {transform: translateX(-8px) rotate(0.02deg);}
50% {transform: translateX(1px) rotate(0deg);}
65% {transform: translateX(6px) rotate(0.02deg);}
80% {transform: translateX(0px) rotate(0deg);}
89% {transform: translateX(-3px) rotate(0.02deg);}
100% {transform: translateX(0) rotate(0deg);}
}
#keyframes range-y {
0% {transform: translateY(0);}
20% {transform: translateY(13px) rotate(0.02deg);}
35% {transform: translateY(-1px) rotate(0deg);}
70% {transform: translateY(-14px) rotate(0.02deg);}
90% {transform: translateY(2px) rotate(0deg);}
100% {transform: translateY(0) rotate(0.02deg);}
}
#-webkit-keyframes range-x {
0% {transform: translateX(0);}
30% {transform: translateX(-8px) rotate(0.02deg);}
50% {transform: translateX(1px) rotate(0deg);}
65% {transform: translateX(6px) rotate(0.02deg);}
80% {transform: translateX(0px) rotate(0deg);}
89% {transform: translateX(-3px) rotate(0.02deg);}
100% {transform: translateX(0) rotate(0deg);}
}
#-webkit-keyframes range-y {
0% {transform: translateY(0);}
20% {transform: translateY(13px) rotate(0.02deg);}
35% {transform: translateY(-1px) rotate(0deg);}
70% {transform: translateY(-14px) rotate(0.02deg);}
90% {transform: translateY(2px) rotate(0deg);}
100% {transform: translateY(0) rotate(0.02deg);}
}
FINAL WORD
You can still tweak the effects a little either way to fit your requirements.
It's not perfect but I hope it helps soften the end effect for your actual animation.
Use a small amount of rotation with the transformation. This forces Firefox to avoid the optimization and resample the image on every frame.
#keyframes optimized {
0%{
transform: translateX(0%);
}
100%{
transform: translateX(200px);
}
}
#keyframes subpixel {
0%{
transform: translateX(0%) rotate(0.1deg);
}
100%{
transform: translateX(200px) rotate(0.1deg);
}
}
div{
width:5px;
height:50px;
background-color: red;
animation-duration:30s;
animation-iteration-count: infinite;
animation-direction:alternate;
animation-timing-function:linear;
}
.optimized{
animation-name: optimized;
margin-bottom:1px;
}
.subpixel{
animation-name: subpixel;
}
<div class="optimized">
</div>
<div class="subpixel">
</div>

Keyframe animation works in Safari not in Chrome

In Chrome, I can run this this animation just fine:
.card {
height: 100px;
width: 100px;
background: red;
}
.cardSway {
-webkit-animation: cardSway 1s ease-in-out infinite;
-moz-animation: cardSway 1s ease-in-out infinite;
-o-animation: cardSway 1s ease-in-out infinite;
}
#-webkit-keyframes cardSway {
0% {-webkit-transform: rotate(1deg) translate(-1px,0px);}
50% {-webkit-transform: rotate(-1deg) translate(1px,0px);}
100% {-webkit-transform: rotate(1deg) translate(-1px,0px);}
}
#-moz-keyframes cardSway {
0% {-moz-transform: rotate(1deg) translate(-1px,0px);}
50% {-moz-transform: rotate(-1deg) translate(1px,0px);}
100% {-moz-transform: rotate(1deg) translate(-1px,0px);}
}
#-o-keyframes cardSway {
0% {-o-transform: rotate(1deg) translate(-1px,0px);}
50% {-o-transform: rotate(-1deg) translate(1px,0px);}
100% {-o-transform: rotate(1deg) translate(-1px,0px);}
}
But this animation doesn't work:
.card {
height: 100px;
width: 100px;
background: red;
}
.cardSway {
-webkit-animation: cardSway 1s ease-in-out infinite;
-moz-animation: cardSway 1s ease-in-out infinite;
-o-animation: cardSway 1s ease-in-out infinite;
animation: cardSway 1s ease-in-out infinite;
}
#-webkit-keyframes cardSway {
0% {-webkit-transform: rotate(1deg) translate(-1px,0px);}
50% {-webkit-transform: rotate(-1deg) translate(1px,0px);}
100% {-webkit-transform: rotate(1deg) translate(-1px,0px);}
}
#-moz-keyframes cardSway {
0% {-moz-transform: rotate(1deg) translate(-1px,0px);}
50% {-moz-transform: rotate(-1deg) translate(1px,0px);}
100% {-moz-transform: rotate(1deg) translate(-1px,0px);}
}
#-o-keyframes cardSway {
0% {-o-transform: rotate(1deg) translate(-1px,0px);}
50% {-o-transform: rotate(-1deg) translate(1px,0px);}
100% {-o-transform: rotate(1deg) translate(-1px,0px);}
}
#keyframes cardSway {
0% {transform: rotate(1deg) translate(-1px,0px);}
50% {transform: rotate(-1deg) translate(1px,0px);}
100% {transform: rotate(1deg) translate(-1px,0px);}
}
The only difference I can find is the presence of the generic keyframe selector is messing with the -webkit- prefixed code. Other Chrome users say it's working fine for them, so I thought it was a busted install. I've reinstalled and it's still a problem for me. Any ideas?
EDIT
Found the answer to my problem in this thread: https://code.google.com/p/chromium/issues/detail?id=331261
'Enable experimental Web Platform features' in chrome://flags caused the prefixing conflict. Disabling it fixed my problem. :)

css3 validation error for keyframes

I having an issue that while using #keyframes in css and checking that in css3 validation it was showing the error "Sorry, the at-rule #-webkit-keyframes is not implemented" like this. I think whether i need to add pre declaration like the css . Because i am new to create an animation using keyframes. Could anyone please provide me the details?
My code is,
#-webkit-keyframes roll{
0% {-webkit-transform: translateX(500px) rotate(360deg);}
100% {-webkit-transform: translateX(0px) rotate(0deg);}
}
#-moz-keyframes roll{
0% {-moz-transform: translateX(500px) rotate(360deg); opacity: 0;}
100% {-moz-transform: translateX(0px) rotate(0deg); opacity: 1;}
}
#-o-keyframes roll{
0% {-o-transform: translateX(500px) rotate(360deg); opacity: 0;}
100% {-o-transform: translateX(0px) rotate(0deg); opacity: 1;}
}
#-ms-keyframes roll{
0% {-ms-transform: translateX(500px) rotate(360deg); opacity: 0;}
100% {-ms-transform: translateX(0px) rotate(0deg); opacity: 1;}
}
#keyframes roll{
0% {transform: translateX(500px) rotate(360deg); opacity: 0;}
100% {transform: translateX(0px) rotate(0deg); opacity: 1;}
}
#-webkit-keyframes moveUp{
0% {-webkit-transform: translateY(40px);}
100% {-webkit-transform: translateY(0px);}
}
#-moz-keyframes moveUp{
0% {-moz-transform: translateY(40px);}
100% {-moz-transform: translateY(0px);}
}
#-o-keyframes moveUp{
0% {-o-transform: translateY(40px);}
100% {-o-transform: translateY(0px);}
}
#-ms-keyframes moveUp{
0% {-ms-transform: translateY(40px);}
100% {-ms-transform: translateY(0px);}
}
#keyframes moveUp{
0% {transform: translateY(40px);}
100% {transform: translateY(0px);}
}
Vendor-specific prefixes are not part of W3C specifications. This is why #keyframes is valid but #-moz-keyframes and #-webkit-keyframes are not.
In this case it is safe to ignore these warnings but generally speaking, validators are pretty useful when developing cross-browser applications.
It may be helpful for you to use a CSS extension language such as SASS or LESS (if you're not using it already) that, with the help of some frameworks, can handle vendor prefixes for you.

Resources