Have a look at this jsfiddle.
I'm using translate3d transformations with a timer function of 'ease':
#keyframes anim {
from {
transform:translate3d(0px, 0px, 0px);
}
50% {
transform:translate3d(100px, 100px,-100px);
}
to {
transform:translate3d(200px, 200px, 0px);
}
}
Why is it not a continuous animation, instead of pausing in the middle? This only happens when using ease-* as the timer function. Is this intended behaviour? If so, how can I make it a continuous animation?
In an animation using keyframes, the timing function is applied to every transition between keyframes.
You can set the timing function at the keyframe, or at the animation; that doesn't change the fact that those are separate functions.
That means that there is not a function that can achieve ease for the full animation easily. (it is fun that it is not easy to get ease :-) )
Since you have only two transitions (3 keyframes), however, an approximate alternative is to set ease-in for the first transition, and ease-out for the second.
For three transitions, the one in the middle would be linear
#-webkit-keyframes anim {
from {
-webkit-transform:translate3d(0px, 0px, 0px);
-webkit-animation-timing-function: ease-in;
}
50% {
-webkit-transform:translate3d(100px, 100px,-100px);
-webkit-animation-timing-function: ease-out;
}
to {
-webkit-transform:translate3d(200px, 200px, 0px);
}
}
fiddle
Notice that there is no timing function to be applied to the last keyframe, because that is applied to the interval and not to the keyframe.
Is this intended behavior?
Yes, that's how the ease-* timing function(s) are suppose to work.
Here is a visual taken from this MDN documentation on animation timing functions.
ease represents the timing function cubic-bezier(0.25, 0.1, 0.25, 1.0)
How can I make it a continuous animation?
Use linear, which represents the timing function cubic-bezier(0.0, 0.0, 1.0, 1.0)
Updated CSS
#a {
animation: anim 1s linear infinite alternate;
-webkit-animation: anim 1s linear infinite alternate;
}
UPDATED EXAMPLE
Related
I'm trying to make a complex animation, so I made the next simple example to ilustrate my problem.
The next code tries to make an object rotate, change its color at 50% of animation and keep it until 100%,
the problem I got is that when it changes from 50% to 100% it doesn't keep the previous keyframe (50%), it becomes transpatent again at 100%.
I've worked with some animation software like blender or animate cc and the default behavior is to keep values of the
properties set in the last keyframe unless you actively change it to something else.
I know that I can set the background property again to red at 100%. but for a real complex animation that would mean repeating A LOT of values,
I'm also aware of the "animation-fill-mode" property which keeps the final state of animation if it is set to "forward",
so I though that if I did that in each step it would behave as I wish but it didn't work :(
Is there a good workaround for this problem without having to repeat each property on every frame?
Can I change the default behaviour?
Note: I thought that if a property is not set on each frame it would default to the initial value (0% frame),
however I didn't set any "transform:rotate" property at 50% and it's not defaulted to 0%'s value, since it interpolates the value between 0% and 100%,
so I have no idea how this really works :/ , some clarification on why does this happen would be really appreceated
.test{
all: unset;
animation-name: rotate_and_change_color;
animation-duration: 3s;
animation-fill-mode: forwards;
animation-timing-function: linear;
animation-direction: normal;
}
#keyframes rotate_and_change_color{
0%{transform: rotate(0deg);
animation-fill-mode: forwards;
}
50%{
background: red;
animation-fill-mode: forwards;
}
100%{transform: rotate(360deg);
animation-fill-mode: forwards;
}
}
One way is to consider multiple animations where you can easily control each property:
.test {
animation-name: rotate, change_color;
animation-duration: 3s;
animation-fill-mode: forwards;
animation-timing-function: linear;
animation-direction: normal;
width:200px;
height:200px;
}
#keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#keyframes change_color {
50%,
100% {
background: red;
}
}
<div class="test">
</div>
Concerning your note this apply to only the last and first state where if you don't specify any value the computed value will be considered (the initial one or the one defined in the style of the element)
If a 0% or from keyframe is not specified, then the user agent constructs a 0% keyframe using the computed values of the properties being animated. If a 100% or to keyframe is not specified, then the user agent constructs a 100% keyframe using the computed values of the properties being animated.ref
For the other states, you have in fact an interpolation considering the value you have defined and the one automatically done (in case you didn't define the 0% and 100%)
I am trying to create a loader animation using CSS3. Here is the code:
http://codepen.io/raaj-obuli/pen/RPeLer
If you look at the code, I've entered the css, in #keyframe defn, for rotating the squares from 0deg to 360deg ( as like below ). But the dices are not rotating. Please help on this and also let me know if you need more details.
#keyframes tilt{
0%{
transform: scale($scaleMin) rotate($rotateStart);
}
50%{
transform: scale($scaleMax);
background: #BC11FF;
box-shadow: 0 0 2px #D467FF;
}
95%,100%{
transform: scale($scaleMin) rotate($rotateEnd);
background: #11A8FF;
box-shadow: none;
}
}
PS. CSS is written using SCSS in the code sample.
It's missing the rotate() in 50% section.
$rotateMid: 225deg;/*added, adjust the value as needed*/
span {
animation: tilt #{$animDuration}s linear infinite; /*changed to linear*/
}
50%{
transform: scale($scaleMax) rotate($rotateMid); /*changed/added*/
}
Updated: http://codepen.io/anon/pen/QbJmbO?editors=110
Differences between the transition timing functions:
ease-in will start the animation slowly, and finish at full speed.
ease-out will start the animation at full speed, then finish slowly.
ease-in-out will start slowly, be fastest at the middle of the animation, then finish slowly.
ease is like ease-in-out, except it starts slightly faster than it ends.
linear uses no easing.
Source: https://stackoverflow.com/a/9636239/483779
In the following animation, I haven't specified a timing function, such as linear or ease-in. It seems to default to ease-in, since it slows down once it begins reaching 0%. What is the actual timing function that is being used in this case (or the default)?
#-webkit-keyframes goleft {
0% { left:400px; }
100% { left:0px; }
}
. goleft {
-webkit-animation: goleft 10s infinite;
animation: goleft 10s infinite;
}
The initial value is ease according to the W3 docs on the subject
The CSS3 specification for Animations spells it out simply:
Name: animation-timing-function
Initial: 'ease'
I'm trying to animate an element rotating like someone starting a top. At first, the element would rotate counter-clockwise before transitioning to rotating clockwise infinitely.
The general CSS I have is here:
div {
animation:
PreRotate 800ms ease-out 0ms 1,
Rotate 500ms linear infinite 800ms;
}
#-keyframes PreRotate {
from { transform:rotate(0deg);}
to { transform:rotate(-360deg);}
}
#-keyframes Rotate {
from { transform:rotate(0deg);}
to { transform:rotate(360deg);}
}
What I expect would happen is that the element would rotate counter clockwise for 800ms once (PreRotate animation) and then rotate clockwise infinitely after 800ms (Rotate animation). From the example http://jsfiddle.net/Fu5V2/6/ though, it seems like every clockwise rotation, the rotation 'hiccups'.
Could someone explain why this is happening and how the desired effect could be achieved? The independent animations seem right but chaining them together messes something up.
I can't tell you exactly why this is happening, but apparently it's caused by the two animations overlapping at some point. If you delay the start of the second animation by something like 50ms, it plays fine:
div {
display:inline-block;
-webkit-animation:
PreRotate 800ms ease-out 0ms 1,
Rotate 500ms linear 850ms infinite;
animation:
PreRotate 800ms ease-out 0ms 1,
Rotate 500ms linear 850ms infinite;
}
#-webkit-keyframes Rotate {
from {-webkit-transform:rotate(0deg);}
to {-webkit-transform:rotate(360deg);}
}
#-webkit-keyframes PreRotate {
from {-webkit-transform:rotate(0deg);}
to {-webkit-transform:rotate(-360deg);}
}
#keyframes Rotate {
from {-webkit-transform:rotate(0deg);}
to {-webkit-transform:rotate(360deg);}
}
#keyframes PreRotate {
from {-webkit-transform:rotate(0deg);}
to {-webkit-transform:rotate(-360deg);}
}
JSFiddle
I just set an animation to a div and it succeeded.
Now I want to get it proved because its delay is too short!
so how can I add the delayed time between animation (0% to 25%) and animation (25% to 50%)
here is the code:
#flow{
position:absolute;
-webkit-animation:mymove 10s ease-in-out;
-webkit-animation-iteration-count:3;
-webkit-animation-delay:1s;
}
#-webkit-keyframes mymove
{
0%{left:5px;}
25%{left:127px;}
50%{left:249px;}
75%{left:371px;}
100%{left:5px;}
}
everyone!Thanks for your attention !I have found the answer but I don't know the Api of the definition of percentage in keyframes!And if you know sth about it ,just give me a hand ,thanks a lot!
#-webkit-keyframes mymove
{
0%{left:5px;}
25%{left:127px;}
26%{left:127px;}
27%{left:127px;}
28%{left:127px;}
29%{left:127px;}
30%{left:127px;}
31%{left:127px;}
32%{left:127px;}
33%{left:127px;}
34%{left:127px;}
35%{left:127px;}
50%{left:249px;}
75%{left:371px;}
100%{left:5px;}
}
I don't think you can delay the single parts of an animation. What you could do, is to use two animations and start them with a delay.
#flow{
position:absolute;
-webkit-animation:
mymove_first 10s 0s 10 ease-in-out,
mymove_second 10s 2s 10 ease-in-out;
}
#-webkit-keyframes mymove_first
{
0%{left:5px;}
25%{left:127px;}
}
#-webkit-keyframes mymove_second
{
50%{left:249px;}
75%{left:371px;}
100%{left:5px;}
}
I ran into this problem, as far as I can find, without jQuery you can't delay the frames.
You can delay the start of the animation.
You can also get the animation to finish the same state as the original frame.
The mean one I use, is being able to do multiple animations, for example:
Your div:
<div id="bannerImg" class="banner-RunAnimation"></div>
Run animation
.RunAnimation {
-webkit-animation: animation1 3s 0s 1 ease-in-out,
animation2 5s 5s 1 ease-out forwards;
}
Animations:
#-webkit-keyframes animation1 {
0% {-webkit-transform: translateY(-0px);}
50% {-webkit-transform: translateY(-150px);}
100% {-webkit-transform: translateY(-150px);
opacity:0;}
}
#-webkit-keyframes animation2 {
0% {transform: translateY(-0px);}
100% {transform: translateY(-150px);}
}
By delaying the animations and using opacity, you can do qutie a few things, if this doesn't help look into jQuery
You can pause it playing with the percentages ( following your example ):
#-webkit-keyframes mymove
{
0%{left:5px;}
25%{left:127px;}
35%{left:127px;}
50%{left:249px;}
75%{left:371px;}
100%{left:5px;}
}
you dont need to put all the percentages between 25% and 35%, the browser is ignoring them.
you move from 0 to 25% from pixel 5 to 127, if your animation is 10 seconds it will take 2.5 seconds to do that, then pause 1 second between 25% to 35% since its the same pixel it wont move then continue to the next animation to pixel 249, it will take 1.5 seconds and so on...
hope this helps!