CSS3弹跳的小球动画

本文展示了如何利用CSS3的动画属性和关键帧实现弹跳小球的效果。通过设置不同的位移、旋转和缩放动画,使得三个小球在页面上呈现出连续的动态效果。

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>

1.png

3.png

2.png

  1. 在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);

            }

        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值