css3 延时动画-【实例】CSS3动画的6个动画属性详解

2023-08-29 0 9,190 百度已收录

CSS3动画有6个动画属性:

其句型为

动画:namedurationtiming-functiondelayiteration-countdirection;

每个属性的描述如下表所示

数值描述

动画名称

指定需要绑定到选择器的关键帧的名称

动画持续时间

指定完成动画所需的时间(以秒或毫秒为单位)。

动画计时函数

指定动画的速度曲线。

动画延迟

指定动画开始前的延迟。

动画迭代计数

指定动画应播放多少次。

动画方向

指定动画是否应反向旋转播放。

实例介绍

比如动画的句子如下:

animation: box_move 1s linear 2s alternate forwards;

那么各个属性值的解释如下:

/* 1. 通过动画集名称调用动画 */
animation-name: box_move;

/* 2.设置动画执行时间 */
animation-duration: 1s;

/* 3. 设置动画的速度类型 */
animation-timing-function: linear;

/* 4. 设置延时执行时间 */
animation-delay: 2s;

/* 5. 动画默认执行次数是1次, infinite: 无限次 */
animation-iteration-count: infinite;

/* 6. 设置动画逆播【动画怎么正着播放,倒着播放的时候也是一样的效果】 normal*/
animation-direction: alternate;

/* 7. 设置动画执行完后的一个状态: 让动画停在结束时候的状态 */
animation-fill-mode: forwards;

需要理解的是css3 延时动画,box_move是动画的名称,即动画集合的名称,通过动画名称来调用动画集合,如下:

@keyframes box_move {
from {}
to {}
}

通过上面的写法,一个完整的动画才算是完整的,即一个动画需要包含两部分,一部分是动画复合属性语句,另一部分是动画集的代码。

案例一:搬运行李

病例疗效:

1. 盒子水平向右移动100pxcss3 延时动画,然后向上移动100px。

2、然后向左连100px,最后向下连100px,回到原点。

3、每次改变方向都必须改变背景颜色,重复执行。

演示下载

完整的 HTML 代码



  
    
    
    
    Document
    
      .box {
        width: 30px;
        height: 30px;
        background-color: blue;
        animation: move 8s linear infinite forwards;
      }
      @keyframes move {
        from {
        }
        25% {
          transform: translateX(100px);
          background-color: red;
        }
        50% {
          transform: translateX(100px) translateY(100px);
          background-color: green;
        }
        75% {
          transform: translateX(0px) translateY(100px);
          background-color: yellow;
        }
        to {
          transform: translateY(0px);
          background-color: blue;
        }
      }
    
  
  
    

  

本例中动画语句为:animation: move 8s LinearInfiniteforward; 其中move是动画episode的名称,8s是动画的执行时间,linear是动画的rate类型(匀速),infinite表示无限循环运动,forwards表示动画结束时离开状态不变。

案例2:抛物线

演示下载

完整的 HTML 代码



  
    
    Document

    
      body {
        position: relative;
background:#eee;
      }
      .animation {
     margin:100px 100px;
        position: absolute;
        width: 50px;
        height: 50px;
        border-radius: 25px;
        background-color: #ed3;
        animation: r 1.5s linear 0s infinite forwards,
          l 1.5s cubic-bezier(0, 0, 1, 0) 0s infinite forwards;
      }
      @keyframes r {
        from {
          left: 0;
        }
        to {
          left: 120px;
        }
      }
      @keyframes l {
        from {
          top: 0;
        }
        to {
          top: 340px;
        }
      }
    
  
  
    

  

这种情况下,动画句子中间会出现一个逗号,表示动画的动画可以同时由多个动画集组成。 本例使用了两个动​​画集r和l,0s的属性值也出现在这里。 表示动画延迟执行时间为0s。

总结

通过本文的学习,我们应该了解CSS3动画动画属性的固有书写方式,并且应该清楚它由两部分组成。 我们需要了解它的6个属性值的具体含义,这样我们才能更准确地做出符合我们期望的动画。

您可能还对以下文章感兴趣

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悟空资源网 css3 css3 延时动画-【实例】CSS3动画的6个动画属性详解 https://www.wkzy.net/game/168659.html

常见问题

相关文章

官方客服团队

为您解决烦忧 - 24小时在线 专业服务