Why CSS animation go smooth only if i am moving mouse pointer? - css

Why, when i moving mouse pointer animation seems to be all-fluent, but if i am not, it is fluent partially (to the half of duration, precisely).
Example (with mouse moving):
Example without moving mouse:
It seems that it waits for end of the animation, and then the picture is showed.
The code which i am working on i present below:
<div class="flip-container-off">
<div class="flipper">
<div class="front">
<div class="image">
<img id="login_image" src="{{ baseUrl }}public/images/login_page/login.png">
</div>
<img id="car1" src="{{ baseUrl }}public/images/login_page/car.png">
<img class="cloud-animation" src="{{ baseUrl }}public/images/login_page/cloud.png">
</div>
<div class="back">
<div class="image">
<img id="login_image" src="{{ baseUrl }}public/images/login_page/payment_required_logo.png">
</div>
<img class="cloud-animation" src="{{ baseUrl }}public/images/login_page/cloud.png">
</div>
</div>
</div>
And the css for it:
.flip-container-on .flipper, .flip-container-on .flipper {
-webkit-transition-delay: 1.5s;
transform: rotateY(180deg);
}
.flip-container-on, .front, .back {
width: 320px;
}
/* flip speed goes here */
.flipper {
transition: 2s;
transform-style: preserve-3d;
position: relative;
}
/* hide back of pane during swap */
.front, .back {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
/* front pane, placed above back */
.front {
z-index: 2;
/* for firefox 31 */
-webkit-transform:rotateY(0deg);
-moz-transform:rotateY(0deg);
-o-transform:rotateY(0deg);
transform:rotateY(0deg);
}
/* back, initially hidden pane */
.back {
-webkit-transform:rotateY(180deg);
-moz-transform:rotateY(180deg);
-o-transform:rotateY(180deg);
transform:rotateY(180deg);
}
And a bit of JQuery:
$(function () {
setTimeout(function () {
$('.flip-container-off').addClass('flip-container-on');
$('.flip-container-off').removeClass('flip-container-off');
},1000);
});
Fiddle:
https://jsfiddle.net/fk2xt8a9/
###################################
EDIT:
I have found the problem, I have got the cloud animation, and this animation interfere with flip animation in some way.
Example:
Code for that cloud i present below:
#media (min-width: 820px) {
.cloud-animation {
display: initial;
left: 52px;
position: absolute;
top: 101px;
animation: animationFrames linear 90s;
animation-iteration-count: infinite;
transform-origin: 50% 50%;
-webkit-animation: animationFrames linear 90s;
-webkit-animation-iteration-count: infinite;
-webkit-transform-origin: 50% 50%;
-moz-animation: animationFrames linear 90s;
-moz-animation-iteration-count: infinite;
-moz-transform-origin: 50% 50%;
-o-animation: animationFrames linear 90s;
-o-animation-iteration-count: infinite;
-o-transform-origin: 50% 50%;
-ms-animation: animationFrames linear 90s;
-ms-animation-iteration-count: infinite;
-ms-transform-origin: 50% 50%;
-webkit-transition-delay: 2s;
transform: rotateY(180deg);
}
}
#keyframes animationFrames {
0% {
transform: translate(0px, 0px);
}
50% {
transform: translate(400px, 0px);
}
100% {
transform: translate(0px, 0px);
}
}
#-moz-keyframes animationFrames {
0% {
-moz-transform: translate(0px, 0px);
}
50% {
-moz-transform: translate(400px, 0px);
}
100% {
-moz-transform: translate(0px, 0px);
}
}
#-webkit-keyframes animationFrames {
0% {
-webkit-transform: translate(0px, 0px);
}
50% {
-webkit-transform: translate(400px, 0px);
}
100% {
-webkit-transform: translate(0px, 0px);
}
}
#-o-keyframes animationFrames {
0% {
-o-transform: translate(0px, 0px);
}
50% {
-o-transform: translate(400px, 0px);
}
100% {
-o-transform: translate(0px, 0px);
}
}
#-ms-keyframes animationFrames {
0% {
-ms-transform: translate(0px, 0px);
}
50% {
-ms-transform: translate(400px, 0px);
}
100% {
-ms-transform: translate(0px, 0px);
}
}
I don't have any idea why it is interfering, but is someone has some idea, i would appreciate it :)
Updated Fiddle: https://jsfiddle.net/fk2xt8a9/1/
(Please run that by run button, place cursor on the html editor and don't move please, because only then the problem occurs)
###################################
POSSIBLE WORKAROUND:
I have improved my code and solved my problem using Jquery:
I put .cloud-animation-off instead of .cloud-animation class
I made setTimeout inside previous setTimeout to exchange these classes to run my animation during flip animation
that caused no interference in both animations :)
Preview:
Example fiddle: https://jsfiddle.net/fk2xt8a9/2/

Related

Multiple CSS animation effects in parallel

To terrify the guys at Pixar (with my animation skills), I am attempting to get a walking effect to work using CSS ...
Unfortunately, I am unable to work two different animation effects in parallel, I want the steps to rotate at a variable rate to the walkRight transition.
Here is my current attempt:
CSS
.wrapper {
position: absolute;
width: 100px;
height: 100px;
right: 0;
animation-name: walkRight;
animation-iteration-count: 1;
animation-timing-function: ease-out;
animation-duration: 10s;
}
.hulk {
-webkit-animation: steps 10s linear 0s;
}
#keyframes walkRight {
0% {
transform: translateX(-400px);
}
100% {
transform: translateX(0);
}
}
#-webkit-keyframes steps {
0% {
-webkit-transform: rotate(0deg);
}
25% {
-webkit-transform: rotate(20deg);
}
50% {
-webkit-transform: rotate(0deg);
}
75% {
-webkit-transform: rotate(-20deg);
}
100% {
-webkit-transform: rotate(0deg);
}
}
Here is an example JsFiddle
You could try to:
Use animation-iteration-count: 10 on hulk class and set is duration to 1s (as walkRight has 10s duration), this means the walk effect will be applied 10 times during the walk.
Prefix all properties using -webkit- to make sure browsers will render your animation properly, you could use autoprefixer (or similar) which does the job for you automatically.
.wrapper {
position: absolute;
width: 100px;
height: 100px;
right: 0;
-webkit-animation-name: walkRight;
animation-name: walkRight;
-webkit-animation-timing-function: ease-out;
animation-timing-function: ease-out;
-webkit-animation-duration: 10s;
animation-duration: 10s;
}
.hulk {
-webkit-animation: steps 1s linear 0s;
-webkit-animation-iteration-count: 10;
animation-iteration-count: 10;
}
#-webkit-keyframes walkRight {
0% {
-webkit-transform: translateX(-400px);
transform: translateX(-400px);
}
100% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
}
#keyframes walkRight {
0% {
-webkit-transform: translateX(-400px);
transform: translateX(-400px);
}
100% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
}
#-webkit-keyframes steps {
0% {
-webkit-transform: rotate(0deg);
}
25% {
-webkit-transform: rotate(20deg);
}
50% {
-webkit-transform: rotate(0deg);
}
75% {
-webkit-transform: rotate(-20deg);
}
100% {
-webkit-transform: rotate(0deg);
}
}
<div class="wrapper">
<img class="hulk" width="100px" src="http://vignette3.wikia.nocookie.net/heroup/images/4/4b/Thing_full_body.png/revision/latest?cb=20120117152657">
</div>
You can use animation-iteration-count on steps animation and set shorter duration. You just need to match ending time for both walk and steps that will repeat itself n number of times, so in this case its about 9 if duration is 1s.
.wrapper {
position: absolute;
width: 100px;
height: 100px;
right: 0;
animation-name: walkRight;
animation-iteration-count: 1;
animation-timing-function: ease-out;
animation-duration: 10s;
}
.hulk {
-webkit-animation: steps 1s linear 0s;
animation-iteration-count: 9;
}
#keyframes walkRight {
0% {
transform: translateX(-400px);
}
100% {
transform: translateX(0);
}
}
#-webkit-keyframes steps {
0% {
-webkit-transform: rotate(0deg);
}
25% {
-webkit-transform: rotate(20deg);
}
50% {
-webkit-transform: rotate(0deg);
}
75% {
-webkit-transform: rotate(-20deg);
}
100% {
-webkit-transform: rotate(0deg);
}
}
<div class="wrapper">
<img class="hulk" width="100px" src="http://vignette3.wikia.nocookie.net/heroup/images/4/4b/Thing_full_body.png/revision/latest?cb=20120117152657">
</div>

I am trying to auto rotate an image after ever 5 seconds from css

I am trying to auto rotate an image after ever 5 seconds from css. My code is working but only on hover but I want on both hover and without hover. So far I have done is given below.
.circle-border:hover {
-webkit-transform: rotate(720deg);
-moz-transform: rotate(720deg);
-o-transform: rotate(720deg);
-ms-transform: rotate(720deg);
transform: rotate(720deg);
transition: transform 0.9s ease 0.3s;
}
<div class="circle-border">
<img class="img-circle" src="images/web.jpg" alt="service 1">
</div>
Thanks in advance
You need an animation not a transtion.
CSS Animations # MDN
This animation is 6s long but the rotation only takes place in the last 1/6th of the duration....which gives us a 1s animation every 5 seconds.
div {
width: 100px;
height: 100px;
background: #663399;
margin: 1em auto;
-webkit-animation-name: spinner;
animation-name: spinner;
-webkit-animation-duration: 6s;
animation-duration: 6s;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
}
#-webkit-keyframes spinner {
83.33% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes spinner {
83.33% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
<div></div>
I used Javascrit to do it however it's still can made with css alone
but maybe usefull, hope it can help
var circle = document.getElementById("test");
if (circle.classList.contains("move")) {
setInterval(function () {
"use strict";
circle.classList.add("move");
}, 2000);
setInterval(function () {
"use strict";
circle.classList.remove("move");
}, 5000);
}
.circle-border {
width:100px;
height:100px;
background-color:#F00;
}
.move {
animation: circle .9s ease 1;
}
.circle-border:hover {
-webkit-transform: rotate(720deg);
-moz-transform: rotate(720deg);
-o-transform: rotate(720deg);
-ms-transform: rotate(720deg);
transform: rotate(720deg);
transition: transform 0.9s ease 0.3s;
}
#keyframes circle {
0% {transform:rotate(0)}
100% { transform:rotate(720deg)}
}
<div id="test" class="circle-border move">
</div>

CSS3 - Animation Scale/Rotate on Hover

I tried and wrote this code but it have a problem, first issue is text inside div will be fuzzy (fluffy)! and second scale animation not play softly, all i want is play animation softly, scale once then rotate infinite on hover.
#-webkit-keyframes socialspin {
from {
-webkit-transform: scale(2) rotate(0deg);
-moz-transform: scale(2)rotate(0deg);
-ms-transform: scale(2) rotate(0deg);
-o-transform: scale(2) rotate(0deg);
transform: scale(2) rotate(0deg);
}
to {
-webkit-transform: scale(2) rotateY(90deg);
-moz-transform: scale(2) rotateY(90deg);
-ms-transform: scale(2) rotateY(90deg);
-o-transform: scale(2) rotateY(90deg);
transform: scale(2) rotateY(90deg);
}
}
Here is JSFiddle Demo
The best way to have a smooth result is not to have a zoom in (scale=2) but a zoom out (scale=0.5), but of course in the opposite state.
And I don't believe that what you want can be achieved with a single animation. I have used 2 elements, and one handles the rotation and the other the scale
#container {
width: 400px;
height: 400px;
}
#container:hover {
-webkit-animation: socialspin 5s linear 0s infinite alternate;
}
#-webkit-keyframes socialspin {
from { -webkit-transform: rotate(0deg); }
to { -webkit-transform: rotateY(90deg); }
}
#keyframes socialspin {
from { transform: rotate(0deg); }
to { transform: rotateY(90deg); }
}
#base {
width: 400px;
height: 400px;
background: yellow;
transform: scale(0.5);
transition: transform 5s;
transform-origin: top left;
font-size: 200%;
}
#container:hover #base {
transform: scale(1);
}
<div id="container">
<div id="base">
<br>
<br>
<br>
HELLLLOOOO!!!
</div>
</div>
We cannot, as of yet, completely make the font clear. This is because you are using an animation. If there was no spinning, the text would not be fuzzy. However, we can try using several font smoothing properties to try and combat this. None of them are very good but they do improve legibility slightly.
Regardless, here is the fix for the second part:
I found a hack. This will remove the blur during the rotation but not during the scaling up.
.square {
width:100px;
height: 100px;
background-color:black;
margin: 50px;
}
p {
-webkit-font-smoothing: antialiased;
color:white;
text-align: center;
padding-top: 35px;
}
.square:hover {
-webkit-animation: scale 1s linear 0s 1, spin 1s linear 1s infinite alternate;
}
.square:hover p{
-webkit-animation: scaletext 1s linear 0s 1;
}
#-webkit-keyframes scale {
from {transform: scale(1); }
to{transform: scale(2);}
}
#-webkit-keyframes scaletext {
from {transform: scale(1); }
to{transform: scale(1);}
}
#-webkit-keyframes spin {
from {transform: rotateY(0deg) scale(2) ;}
to {transform: rotateY(90deg) scale(2);}
}
<div class="square">
<p>Some text</p>
</div>
(I removed the prefixes to condense the answer)
here is the example and the point is first to describe all features in the main div as defaults because animation uses main elements rules to calculate time etc.
and second point here you used 90 degrees to turn but a complete turning back can be done by 180 degrees which is the angle of a line
here is the code
--update--
here is the exxample you can see scale animates the problem was in your animation scaling started from 2 and ended by 2 so there was no animation for that
--update--
here we go if you run transition first and by the time while transition is running make animation wait by delay time of animation it works fine you can see here
div {
width: 200px;
height: 200px;
background: yellow;
-webkit-transform:scale(1) rotate(0);
transform:scale(1) rotate(0);
margin-left:200px;
margin-top:50px;
transition:-webkit-transform .5s linear;
transition:transform .5s linear;
}
div:hover {
-webkit-transform:scale(2) rotate(0);
transform:scale(2) rotate(0);
-webkit-animation: socialspin 5s linear .5s infinite alternate;
-moz-animation: socialspin 5s linear .5s infinite alternate;
}
#-webkit-keyframes socialspin {
from {
-webkit-transform: scale(2) rotate(0deg);
transform:scale(2) rotate(0deg);
}
to {
-webkit-transform: scale(2) rotateY(180deg);
transform: scale(2) rotateY(180deg);
}
}

IE: Child element loses animation when parent is temporary hidden

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.

How to apply css3 animation from current translation?

I have a box that's currently translated, but when I apply a shake animation to it, it jumps to the upper left side of the screen.
I'd like to shake it from it's current position. How might I do this?
Here's my jsfiddle. Please view in a webkit browser (chrome/safari)
http://jsfiddle.net/foreyez/atv7R/
CSS:
div {
background:red;
width:100px;
height:100px;
-webkit-transform: translate3d(50px, 50px, 0px);
}
#-webkit-keyframes shake {
0% { -webkit-transform: translateX(3px); }
50% { -webkit-transform: translateX(-3px); }
100% { -webkit-transform: translateX(0); }
}
.shake {
-webkit-animation-name: shake;
-webkit-animation-duration: 150ms;
-webkit-animation-iteration-count: 20;
-webkit-animation-timing-function: linear;
}
HTML:
<div></div>
JAVASCRIPT:
$('div').addClass('shake')
I ended up using move.js
http://visionmedia.github.io/move.js/
they do what I want with the .then() command. One of these days I'm gonna look at the code to see how they do it because it's all done with translates.
You could animate the position with jQuery and then add the add the class with the keyframe animation to get the desired effect.
http://jsfiddle.net/atv7R/3/
$('div').animate({
top: 50,
left: 50
}, 1000).addClass('shake');
or you could acomplish the same thing with css:
http://jsfiddle.net/atv7R/5/
div {
position:absolute;
top: 10px;
left:10px;
background:red;
width:100px;
height:100px;
}
#-webkit-keyframes shake {
0% {
-webkit-transform: translate3d(0px, 0px, 0px);
}
50% {
-webkit-transform: translate3d(3px, 3px, 0px);
}
100% {
-webkit-transform: translate3d(0px, 0px, 0px);
}
}
.shake {
top: 50px;
left: 50px;
-webkit-transition: top 1s, left 1s;
-webkit-animation-name: shake;
-webkit-animation-delay: 1s;
-webkit-animation-duration: 150ms;
-webkit-animation-iteration-count: 20;
-webkit-animation-timing-function: linear;
}

Resources