css动画小球

@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咻~

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容