I have this animation, it is currently meant to be only fast at the start, however when it reaches 85% - 95% the cubic-Bezier should be continuously slow instead of starting from point 0 again and creating another fast start motion. Is there any way to add multiple cubic-Beziers for each animation state change or have the easing-function continuous from state to state?
.animate-winner {
animation: rollWinnerBait 9s cubic-bezier(0,.9,.76,.99) forwards normal 1
}
#keyframes rollWinnerBait {
0% {
transform: translateX(4988px)
}
85% {
transform: translateX(-80px)
}
95% {
transform: translateX(11px)
}
98% {
transform: translateX(-9px)
}
100% {
transform: translateX(0px)
}
}
Update the timing function inside the animation:
.animate-winner {
animation: rollWinnerBait 5s cubic-bezier(0, .9, .76, .99) forwards;
width:100px;
height:100px;
margin:5px;
background:red;
}
.animate-winner.new {
animation: rollWinnerBait-new 5s cubic-bezier(0, .9, .76, .99) forwards;
}
#keyframes rollWinnerBait {
0% {
transform: translateX(4988px)
}
85% {
transform: translateX(-80px);
}
95% {
transform: translateX(11px)
}
98% {
transform: translateX(-9px)
}
100% {
transform: translateX(0px);
}
}
#keyframes rollWinnerBait-new {
0% {
transform: translateX(4988px)
}
85% {
transform: translateX(-80px);
animation-timing-function:linear;
}
95% {
transform: translateX(11px)
}
98% {
transform: translateX(-9px)
}
100% {
transform: translateX(0px);
animation-timing-function:linear;
}
}
<div class="animate-winner"></div>
<div class="animate-winner new"></div>
Related
I am trying to create a CSS animation to make a plane take off from a runway and then make a slight curve to the right as it gains altitude. To accomplish this, I believe I need to adjust scale, rotation and x/y coordinates in the keyframes. I've been playing around with it for a while but I can't figure out how to make it look natural. What's the best way to calculate the various values I will need to make a smooth curve up and to the right?
.container {
width:700px;
height:100%;
}
img {
max-width:100%;
}
.airplane {
position:absolute;
bottom:0;
animation: takeoff linear 2s forwards;
}
#keyframes takeoff {
0% {
transform: translate(0,0) rotate(0);
}
5% {
transform: translate(0,0) rotate(0) scale(.9);
}
10% {
transform: translate(0,0) rotate(0) scale(.9);
}
20% {
transform:translate(0,0) rotate(0) scale(0.85);
}
30% {
transform:translate(0,0) rotate(0) scale(0.80);
}
40% {
transform:translate(0,0) rotate(0) scale(0.75);
}
50% {
transform:translate(0,0) rotate(5deg) scale(0.5);
}
60% {
transform:translate(0,0) rotate(5deg) scale(0.45);
}
70% {
transform: translate(150px, -200px) rotate(10deg) scale(.4);
}
80% {
transform:translate(200px,-300px) rotate(20deg) scale(0.35);
}
90% {
transform:translate(250px,-400px) rotate(30deg) scale(0.3);
}
100% {
transform:translate(300px,-500px) rotate(30deg) scale(0.3);
}
}
<div class="container">
<img class="airplane" src=https://i.stack.imgur.com/DhHSc.png" />
</div>
You can probably consider an animation on the container to make it easier to handle:
.container {
position: absolute;
bottom: 0;
animation: takeoff-alt ease-in 1s 1s forwards;
}
img {
max-width:100%;
}
.airplane {
animation: takeoff linear 2s forwards;
}
#keyframes takeoff {
to {
transform: scale(0.1);
}
}
#keyframes takeoff-alt {
100% {
transform: rotate(30deg) translateY(-100%);
}
}
body {
overflow:hidden;
}
<div class="container">
<img class="airplane" src="https://i.stack.imgur.com/DhHSc.png" />
</div>
I'm trying to make a css rotation animation that has different speeds at different degree points.
Here is the animation I'm trying to make:
Here is a Pen of what I currently have and below is the code:
img {
width: 125px;
}
body {
text-align: center;
}
#loading {
-webkit-animation: slow 1.5s linear 1.5s, fast 1s linear 1s, slow2 1s linear 1s;
-webkit-animation-iteration-count: infinite;
}
#-webkit-keyframes slow {
from {
-webkit-transform: rotate(0deg)
}
to {
-webkit-transform: rotate(90deg)
}
}
#-webkit-keyframes fast {
from {
-webkit-transform: rotate(91deg)
}
to {
-webkit-transform: rotate(270deg)
}
}
#-webkit-keyframes slow2 {
from {
-webkit-transform: rotate(271deg)
}
to {
-webkit-transform: rotate(359deg)
}
}
<img id="loading" src="https://i.imgur.com/VpLRlbZ.png">
So, in the example you provided, the effect is only done by modifying the animation-timing-function css property.
Then you'll have only one animation
div {
width:100px;
height:100px;
background:red;
animation:rotate 3s infinite;
animation-timing-function: cubic-bezier(1,0,.5,1);
}
#-webkit-keyframes rotate {
from { -webkit-transform: rotate(0deg) }
to { -webkit-transform: rotate(360deg) }
}
<div></div>
You can find more informations here : https://callmenick.com/dev/level-up-animations-cubic-bezier/
But the point is, use only one animation and modify speed at different angles value modifying this animation-timing-function.
EDIT Added a closer cubic bezier timing function thanks to #SirExotic comment.
You can just divide the animation keyframes into several ones, and adjust the percentages of each to set the relative speeds:
The natural percentage for 90deg would be 25% . Any value higher than that will make this part slower
img {
width: 125px;
}
body {
text-align: center;
}
#loading {
animation: rotate 4s linear infinite;
}
#keyframes rotate {
0% {
transform: rotate(0deg)
}
40% {
transform: rotate(90deg)
}
60% {
transform: rotate(270deg)
}
100% {
transform: rotate(360deg)
}
}
<img id="loading" src="https://i.imgur.com/VpLRlbZ.png">
I'm trying to make a ship moves from left to right and from top to bottom at the same time (it describes a straight downward line). I want to assign different speeds to the animation in the 'X' and 'Y' axis. I mean I want little ship to move slower when moving from left to right, and faster when moving from top to bottom, but I haven't been able to accomplish this because I don't know how to separate the speed of the different animated properties. I would highly appreciate any suggestion. Here is my code:
body {
overflow-x:hidden;
}
div {
width: 150px;
height: 150px;
top: 20px;
background-image: url('https://s-media-cache-ak0.pinimg.com/originals/c2/bb/ae/c2bbaed0207deef5775af9c01e1b31ba.jpg');
position: relative;
background-size: cover;
animation: mymove 5s linear infinite;
}
#-webkit-keyframes mymove {
0% {
left:-1%;
top:-1%;
transform: rotate(5deg)
}
20% {
transform: rotate(-5deg)
}
40%
{
transform: rotate(5deg)
}
60% {
transform: rotate(-5deg)
}
80%{
transform: rotate(5deg)
}
100% {
left:100%;
top:100%;
transform: rotate(-5deg)
}
}
<div></div>
Thanks in advance!
Try this updated keyframe
#-webkit-keyframes mymove {
0% {
left:-1%;
transform: rotate(5deg)
}
20% {
transform: rotate(-5deg)
}
40%
{
left:90%;
transform: rotate(5deg)
}
60% {
transform: rotate(90deg) translate(0px,0px)
}
80%{
transform: rotate(95deg) translate(210px,0px)
}
100% {
left:90%;
transform: rotate(90deg) translate(410px,0px)
}
}
Updated answer#1
ship will travel diagonally
#-webkit-keyframes mymove {
0% {
transform: translate(0px,0px) rotate(55deg)
}
10% {
transform: translate(100px,50px) rotate(60deg)
}
20% {
transform: translate(200px,100px) rotate(55deg)
}
30% {
transform: translate(300px,150px) rotate(60deg)
}
40% {
transform: translate(400px,200px) rotate(55deg)
}
50% {
transform: translate(500px,250px) rotate(60deg)
}
60% {
transform: translate(600px,300px) rotate(55deg)
}
70% {
transform: translate(700px,350px) rotate(60deg)
}
80% {
transform: translate(800px,400px) rotate(55deg)
}
90% {
transform: translate(900px,450px) rotate(60deg)
}
100% {
transform: translate(1000px,500px) rotate(55deg)
}
}
Is there a way to pulsate opacity from 0 to 1 (repeat) slowly with a CSS3 keyframes transformation, infinitely? Or does this require jQuery or Javascript with a transition opacity inside a class that is toggled on an interval?
I'm trying to work it into my orbit transformations (below). (I'm working on a live wallpaper background effect with multiple opaque images floating in a sidebar image on an installer application I'm building in Objective C.)
.orbit1
{
animation: myOrbit 200s linear infinite;
}
.orbit2
{
animation: myOrbit2 200s linear infinite;
}
#keyframes myOrbit1
{
from { transform: rotate(0deg) translateX(150px) rotate(0deg) }
to { transform: rotate(360deg) translateX(150px) rotate(-360deg) }
}
#keyframes myOrbit2
{
from { transform: rotate(360deg) translateX(250px) rotate(-360deg) }
to { transform: rotate(0deg) translateX(250px) rotate(0deg) }
}
You can do it by adding multiple animations to the element, for example:
.orbit1
{
/* added for example reasons */
position :absolute;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
width: 200px;
height: 200px;
background: red;
/* ---------- */
animation: myOrbit1 20s linear infinite, Pulsate 4s linear infinite;
}
#keyframes myOrbit1
{
from { transform: rotate(0deg) translateX(150px) rotate(0deg) }
to { transform: rotate(360deg) translateX(150px) rotate(-360deg) }
}
#keyframes Pulsate {
from { opacity: 1; }
50% { opacity: 0; }
to { opacity: 1; }
}
<div class="orbit1"></div>
I'ved modified some of your parameters (like the speed of the animation and the opacity minimum) and added some spoof styling for the element for the purpose of the example.
Edit
I had originally thought that the multiple rotate() declarations were in error, but #vals informed me why it was there (to create a counter rotation on the object). I've updated the answer, and learned something new.
I'm looking at optimising CSS animations for performance.
From what I can find out using
.item { transform: translate(-25px,-50px)
is much more efficient than
.item { left: -25px; top: -50px }
I've setup a little animation that move and rotates a box .balloon which as multiple steps to the animation. The problem is though the animation becomes very jerky, even with positioning ans rotation declared for each step
Here is my standard CSS
#keyframes balloon {
0%,100% { left:809px; top:50px; transform: rotate(0deg) }
10% { transform: rotate(-9deg) }
25%,75% { top:25px }
50% { left:235px;top:75px }
45% { transform: rotate(3deg) }
75% { transform: rotate(12deg) }
}
This is my optimised CSS, which is where the jerky animation comes in to effect
#keyframes balloon {
0% { transform: translate(0,0) rotate(0deg) }
10% { transform: translate(-57.5px,-10px) rotate(-9deg) }
25% { transform: translate(-143.75px,-25px) rotate(-4deg) }
45% { transform: translate(-517.5px,22.5px) rotate(3deg) }
50% { transform: translate(-575px,25px) rotate(4.5deg) }
75% { transform: translate(-287.5px,-25px) rotate(12deg) }
100% { transform: translate(0,0) rotate(0deg) }
}
Is there an alternative solution for this?
I've put a CodePen together here.
In your animation-property, try to add a value for the animation-timing-function
Something like
animation: balloon 15s infinite linear;
would make it more smooth.