css动画弹球

7 篇文章 0 订阅

@keyframes *** {0%—100%}

animation: animationName time [ style …]

##源码

css

...
.sport {
            position: relative;
            width: 500px;
            height: 400px;
            border: 1px solid #F6D66E;
            background-color: greenyellow;
        }
        
        #pole {
            position: absolute;
            z-index: 1;
            bottom: 10px;
            left: 10px;
            overflow: hidden;
            width: 180px;
            height: 8px;
            border-radius: 3px;
            background: #000;
            line-height: 20;
            -moz-animation: pole 3s linear;
            -webkit-animation: pole 3s linear;
            -o-animation: pole 3s linear;
            -ms-animation: pole 3s linear;
            animation: pole 3s linear;
        }
        
        #ball {
            position: absolute;
            z-index: 1;
            bottom: 20px;
            left: 90px;
            overflow: hidden;
            width: 30px;
            height: 30px;
            border-radius: 15px;
            box-shadow: 0 0 10px rgba(107, 22, 22, 0.425);
            background: #eee;
            /* 兼容性处理
            background: -moz-linear-gradient(top, #fff, skyblue);
            background: -webkit-linear-gradient(top, #fff, skyblue);
            background: -o-linear-gradient(top, #fff, skyblue);
            background: -ms-linear-gradient(top, #fff, skyblue);
            */
            background: linear-gradient(top, #fff, skyblue);
            line-height: 20;
            -moz-animation: ball 3s linear;
            -webkit-animation: ball 3s linear;
            -o-animation: ball 3s linear;
            -ms-animation: ball 3s linear;
            animation: ball 3s linear;
        }
/* 小球动画 */
 @keyframes ball {
            0% {
                transform: translate(0, 0);
            }
            5% {
                transform: translate(-90px, -100px);
            }
            18% {
                transform: translate(0, -350px);
            }
            35% {
                transform: translate(200px, 0);
            }
            46% {
                transform: translate(380px, -160px);
            }
            60% {
                transform: translate(250px, -350px);
            }
            78% {
                transform: translate(60px, 0);
            }
            100% {
                transform: translate(0, 0);
            }
        }
/* 杆动画 */
@keyframes pole {
            0% {
                transform: translate(0, 0);
            }
            6% {
                transform: translate(260px, 0);
            }
            20% {
                transform: translate(300px, 0);
            }
            30% {
                transform: translate(300px, 0);
            }
            40% {
                transform: translate(200px, 0);
            }
            65% {
                transform: translate(40px, 0);
            }
            79% {
                transform: translate(0, 0);
            }
            100% {
                transform: translate(0, 0);
            }
        }
...
/* 还可以自由发挥,加入更复杂的动画哦 */

html部分

<div class="sport">
        <span id="ball">飞球</span>
        <span id="pole">阻拦杆</span>
</div>

输出结果

如果对你有所帮助,欢迎点赞收藏哦,共同进步哦!!

快去试试吧

blog咻~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值