這個小 demo 的關鍵在於用 @keyframes 把 top 的位移與 scaleX、scaleY 的形變綁在一起:落下時壓扁、彈起時拉長,再搭配 ease-in / ease-out 的節奏切換,反彈的手感就會真實很多。
<div class="ball"></div>
body { background: #fff; }
.ball {
position: absolute;
top: 0;
left: 50%;
z-index: 11;
margin: 0 0 0 -8px;
width: 200px;
height: 130px;
border-radius: 50%;
background: url(/School/UploadFiles_7810/201603/20160313141641745.gif?1) #57abdb;
animation: jump 4s infinite forwards;
}
@keyframes jump {
0%, 100% {
top: 0%;
transform: scaleX(1.1) scaleY(0.9);
animation-timing-function: ease-in;
}
40% {
top: 80%;
transform: scaleX(1) scaleY(1);
}
55% {
top: 90%;
transform: scaleX(1.8) scaleY(0.2);
animation-timing-function: ease-in-out;
}
65% {
top: 30%;
transform: scaleX(.6) scaleY(1.4);
animation-timing-function: ease-out;
}
80% {
transform: scaleX(1) scaleY(1);
}
}
幾個可以玩的細節:55% 那格把 Y 軸壓到 0.2、X 軸拉到 1.8,是觸地瞬間的挤压感;65% 反向拉長模擬離地加速;每個 keyframe 各自指定 timing-function,讓每一段的加速曲線都不同,整體節奏會比全域統一設定自然得多。