我正在尝试为漂浮在屏幕上的气球设置动画。我以为我会在Y轴上使用线性运动动画,而在X轴上使用类似正弦的摆运动来模拟气球在水平方向上来回浮动。我对结果并不满意,它看起来不错。您对我如何改善动画有什么建议吗?
这是我想到的CSS动画:
.balloon {
background-image: url(https://i.imgur.com/QJZPw2X.png);
width: 180px;
height: 300px;
background-size: contain;
position: absolute;
bottom: 0%;
animation: move_y 30s linear forwards, oscil1 6s infinite;
left: 45%;
}
@keyframes move_y {
from {
bottom: -10%;
}
to {
bottom: 100%;
}
}
@keyframes oscil1 {
from {
translate: 0 0;
transform: rotate(0deg);
animation-timing-function: cubic-bezier(0.1, 0.3, 0.3, 1);
}
25% {
translate: 10px 0;
transform: rotate(3deg);
animation-timing-function: cubic-bezier(0.7, 0.0, 0.9, 0.7);
}
50% {
translate: 0 0;
transform: rotate(0deg);
animation-timing-function: cubic-bezier(0.1, 0.3, 0.3, 1);
}
75% {
translate: -10px 0;
transform: rotate(-3deg);
animation-timing-function: cubic-bezier(0.7, 0.0, 0.9, 0.7);
}
to {
translate: 0 0;
transform: rotate(0deg);
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="balloon">
</div>
</body>
</html>