html css 实现小球跳动动画

11,791次阅读
没有评论

共计 1979 个字符,预计需要花费 5 分钟才能阅读完成。

在学习 html5 和 css3 的时候,用到了动画效果 animation。

具体步骤是:

  1. 定义一个大盒子 box,box-content 代表小球,circle 代表小洞。。

    

2. 设置外层盒子的样式,采用 display 属性,以列的形式进行排序。。

内部元素位置为底部对齐

      .box {
            width: 100px;
            height: 300px;
            /* border: 1px solid #000; */
            margin:0 auto;
            display: flex;
            flex-direction: column;
            justify-content: flex-end;
            align-items: center;
        }

3. 设置小球样式,宽高各为 50px,边框弧度为百分之 50,背景颜色为渐变色,

     .box-content {
            width: 50px;
            height: 50px;
            /* border: 1px solid #000; */
            border-radius: 50%;
            /* margin: 20px auto; */
            background: linear-gradient(0deg,blue,red);
            box-shadow: 0 0 5px  rgba(0,0,0,0.5);
            animation: animal 2s infinite alternate linear;
      }

4. 设置 circle 样式,

.circle{
            width: 50px;
            height: 10px;
            background-color: rgba(0,0,0,0.5);
            border-radius: 50%;
            animation: animal1 2s infinite alternate linear;
}

5. 设置动画效果,

        /* 小洞的动画效果 */
        @keyframes animal1 {
              0% {transform: scale(1.2);
              }
              100% {transform: scale(0.5);
              }
        }
        /* 小球的动画效果 */
        @keyframes animal {
            0% {transform: translateY(0);
            }
            100% {transform: translateY(-250px);
            }
        }

效果如下:

html   css 实现小球跳动动画

全部代码如下:




    
    
    
    Document
    


    

原文地址: html css 实现小球跳动动画

    正文完
     0
    Yojack
    版权声明:本篇文章由 Yojack 于2024-10-07发表,共计1979字。
    转载说明:
    1 本网站名称:优杰开发笔记
    2 本站永久网址:https://yojack.cn
    3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
    4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
    5 本站所有内容均可转载及分享, 但请注明出处
    6 我们始终尊重原创作者的版权,所有文章在发布时,均尽可能注明出处与作者。
    7 站长邮箱:laylwenl@gmail.com
    评论(没有评论)