CSS3弹跳的小球动画

<style>
*{
margin: 0;
padding: 0;
list-style: none;
}
html,body{
width: 100%;
height: 100%;
}
body{
min-height: 100vh;
background-color: #eee;
color: #fff;
}
.container{
width: 580px;
height: 143px;
/* outline: 1px dashed red; */
/* 绝对定位 */
/* 使用这种写法,也可以让 一个容器 水平,垂直 居中显示 */
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
margin: auto;
}
.container .ball{
/* 浮动 */
float: left;
margin-right: 50px;
}
/* :last-of-type 序选择器 ---表示容器中的最后一个元素 */
.container .ball:last-of-type{
margin-right: 0;
}
.container .ball img{
width: 160px;
}
/* 给三个小盒子,添加 定位,让他们 最初 “出现在哪里”----这个地方的定位,
和布局没有关系,和你要做的 弹跳的 位置 有关系!! */
.ball{
position: absolute;
top: 0;
left: 50%;
margin-left: -80px;
}
/* css3中的动画序列(排列动画)---给一个元素身上,添加多个动画效果 */
.ball1{
/* 动画
tiao1 动画名称
0.5s 动画完成时间
ease-in 速度
1 动画执行的次数
forwards 动画执行到最后一帧停止
*/
/* tiao2 0.2s ease-out 0.5s 1 forwards 其中, 0.5s动画延迟时间,表示 时间到0.5秒的时候,再执行tiao2这个动画 */
/*
*/
animation: tiao1 0.5s ease-in 1 forwards,
tiao2 0.2s ease-out 0.5s 1 forwards,
tiao3 0.2s ease-out 0.7s 1 forwards,
tiao4 0.15s ease-out 0.9s 1 forwards,
tiao5 0.15s ease-in 1.05s 1 forwards,
leftMove 0.4s ease-out 1.2s 1 forwards;
}
.ball2{
animation: tiao1 0.5s ease-in 1 forwards,
tiao2 0.2s ease-out 0.5s 1 forwards,
tiao3 0.2s ease-out 0.7s 1 forwards,
tiao4 0.15s ease-out 0.9s 1 forwards,
tiao5 0.15s ease-in 1.05s 1 forwards,
middle 0.4s ease-out 1.2s 1 forwards;
}
.ball3{
animation: tiao1 0.5s ease-in 1 forwards,
tiao2 0.2s ease-out 0.5s 1 forwards,
tiao3 0.2s ease-out 0.7s 1 forwards,
tiao4 0.15s ease-out 0.9s 1 forwards,
tiao5 0.15s ease-in 1.05s 1 forwards,
rightMove 0.4s ease-out 1.2s 1 forwards;
}
@keyframes tiao1 {
0%{
/* 变形--位移 */
transform: translateY(-500px);
}
100%{
transform: translateY(0);
}
}
@keyframes tiao2 {
0%{
transform: translateY(0);
}
100%{
transform: translateY(-100px);
}
}
@keyframes tiao3 {
0%{
transform: translateY(-100px);
}
100%{
transform: translateY(0);
}
}
@keyframes tiao4 {
0%{
transform: translateY(0);
}
100%{
transform: translateY(-50px);
}
}
@keyframes tiao5 {
0%{
transform: translateY(-50px);
}
100%{
transform: translateY(0);
}
}
@keyframes leftMove {
0%{
transform: translateX(0);
}
100%{
transform: translateX(-300px) scale(1.6) rotate(360deg);
}
}
@keyframes middle {
0%{
transform: translateX(0);
}
100%{
transform: translateX(0) scale(1.6) rotate(360deg);
}
}
@keyframes rightMove {
0%{
transform: translateX(0);
}
100%{
transform: translateX(300px) scale(1.6) rotate(360deg);
}
}
</style>
</head>
<body>
<div class="container">
<div class="ball ball1"><img src="img/1.png" alt=""></div>
<div class="ball ball2"><img src="img/2.png" alt=""></div>
<div class="ball ball3"><img src="img/3.png" alt=""></div>
</div>
</body>



-
在body标签中引入三张图片和css样式
<div class="container">
<div class="ball ball1"><img src="img/1.png" alt=""></div>
<div class="ball ball2"><img src="img/2.png" alt=""></div>
<div class="ball ball3"><img src="img/3.png" alt=""></div>
</div>
2.css样式
设置三张图片位置,大小
.container{
width: 580px;
height: 143px;
/* outline: 1px dashed red; */
/* 绝对定位 */
/* 使用这种写法,也可以让 一个容器 水平,垂直 居中显示 */
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
margin: auto;
}
.container .ball{
/* 浮动 */
float: left;
margin-right: 50px;
}
/* :last-of-type 序选择器 ---表示容器中的最后一个元素 */
.container .ball:last-of-type{
margin-right: 0;
}
.container .ball img{
width: 160px;
}
3.给三个小盒子,添加 定位,让他们 最初“出现在哪里”----这个地方的定位,
和布局没有关系,和你要做的 弹跳的 位置 有关系!!
.ball{
position: absolute;
top: 0;
left: 50%;
margin-left: -80px;
}
4. css3中的动画序列(排列动画)---给一个元素身上,添加多个动画效果 ,
tiao1 动画名称
0.5s 动画完成时间
ease-in 速度
1 动画执行的次数
forwards 动画执行到最后一帧停止
tiao2 0.2s ease-out 0.5s 1 forwards 其中, 0.5s动画延迟时间,表示 时间到0.5秒的时候,再执行tiao2这个动画
.ball1{
animation: tiao1 0.5s ease-in 1 forwards,
tiao2 0.2s ease-out 0.5s 1 forwards,
tiao3 0.2s ease-out 0.7s 1 forwards,
tiao4 0.15s ease-out 0.9s 1 forwards,
tiao5 0.15s ease-in 1.05s 1 forwards,
leftMove 0.4s ease-out 1.2s 1 forwards;
}
.ball2{
animation: tiao1 0.5s ease-in 1 forwards,
tiao2 0.2s ease-out 0.5s 1 forwards,
tiao3 0.2s ease-out 0.7s 1 forwards,
tiao4 0.15s ease-out 0.9s 1 forwards,
tiao5 0.15s ease-in 1.05s 1 forwards,
middle 0.4s ease-out 1.2s 1 forwards;
}
.ball3{
animation: tiao1 0.5s ease-in 1 forwards,
tiao2 0.2s ease-out 0.5s 1 forwards,
tiao3 0.2s ease-out 0.7s 1 forwards,
tiao4 0.15s ease-out 0.9s 1 forwards,
tiao5 0.15s ease-in 1.05s 1 forwards,
rightMove 0.4s ease-out 1.2s 1 forwards;
}
5.设置图片弹跳动画的关键帧
@keyframes tiao1 {
0%{
/* 变形--位移 */
transform: translateY(-500px);
}
100%{
transform: translateY(0);
}
}
@keyframes tiao2 {
0%{
transform: translateY(0);
}
100%{
transform: translateY(-100px);
}
}
@keyframes tiao3 {
0%{
transform: translateY(-100px);
}
100%{
transform: translateY(0);
}
}
@keyframes tiao4 {
0%{
transform: translateY(0);
}
100%{
transform: translateY(-50px);
}
}
@keyframes tiao5 {
0%{
transform: translateY(-50px);
}
100%{
transform: translateY(0);
}
}
@keyframes leftMove {
0%{
transform: translateX(0);
}
100%{
transform: translateX(-300px) scale(1.6) rotate(360deg);
}
}
@keyframes middle {
0%{
transform: translateX(0);
}
100%{
transform: translateX(0) scale(1.6) rotate(360deg);
}
}
@keyframes rightMove {
0%{
transform: translateX(0);
}
100%{
transform: translateX(300px) scale(1.6) rotate(360deg);
}
}
本文展示了如何利用CSS3的动画属性和关键帧实现弹跳小球的效果。通过设置不同的位移、旋转和缩放动画,使得三个小球在页面上呈现出连续的动态效果。

752

被折叠的 条评论
为什么被折叠?



