Issue
I've started to learn about keyframe animation in CSS3. One think I've noticed is that, no matter how I ""time" things with keyframe animations, the transitions are always smooth.
For example; a background color change from 50% to 100%, is a smooth transition as the animation plays from 50% to 100%.
What I'm trying to achieve is a way of doing the animation with an "instant" type of value change..
Again, an example would be: If 50% value of BG is red and 100% value of BG is blue; the animation should stay red till it reaches to 100% and instantly changes to blue when it is 100% completed.
I'm not sure if my terminology is right or wrong, but some direction would be perfect in any case.
Solution
You can use steps as your timing-function to pause the animation until the next keyframe
CSS:
-webkit-animation-timing-function: steps(1, end);
-moz-animation-timing-function: steps(1, end);
-ms-animation-timing-function: steps(1, end);
-o-animation-timing-function: steps(1, end);
animation-timing-function: steps(1, end);
Sample code:
@keyframes quick {
0% {
background-color:green;
}
50% {
-webkit-animation-timing-function: steps(1, end);
-moz-animation-timing-function: steps(1, end);
-ms-animation-timing-function: steps(1, end);
-o-animation-timing-function: steps(1, end);
animation-timing-function: steps(1, end);
background-color:blue;
}
100% {
background-color:red;
}
}
@-o-keyframes quick {
0% {
background-color:green;
}
50% {
-o-animation-timing-function: steps(1, end);
background-color:blue;
}
100% {
background-color:red;
}
}
@-moz-keyframes quick {
0% {
background-color:green;
}
50% {
-moz-animation-timing-function: steps(1, end);
background-color:blue;
}
100% {
background-color:red;
}
}
@-webkit-keyframes quick {
0% {
background-color:green;
}
50% {
-webkit-animation-timing-function: steps(1, end);
background-color:red;
}
100% {
background-color:blue;
}
}
body {
height:100%;
width:100%;
animation:quick 3s;
-moz-animation:quick 3s;
-webkit-animation:quick 3s;
-o-animation:quick 3s;
-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
-o-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
Answered By - extramaster
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.