动画的基本使用

—— animation调用

目录

定义及语法

动画的调用

重点注意

常用属性

调用速写

典型例子

波点效果

放映图标效果

打字机及循环移动效果


  • 定义及语法

使用:用@keyframes定义动画,属于CSS3范畴;

格式:

 @keyframes 动画名称  {
         from / 0% {
                 起始态;
          }
          n% {
              中间态(可多个);
          }
          to / 100% {
                 末尾态;
          }
     }
  • 动画的调用

调用:用animation属性调用,属于CSS语法;

格式:

在对应的div内部填写:

div{

animation-name:动画名称;

animation-duration:持续时间(s);

}
  • 重点注意

  1. 定义时,百分比要为整数;
  2. 对应百分比就是  总时间的划分  。
  3. 运用多组动画时,由于层叠性,在调用下要用逗号隔开。
  • 常用属性

  1. @keyframes —— 规定动画;
  2. animation-name —— 动画名称;
  3. animation-timing-function —— 速度曲线 — — 默认:ease、匀速:linear、间隔步长:steps(n),可制作打字机、动图效果;
  4. animation-duration —— 动画一个周期花费时间;
  5. animation-delay —— 动画何时开始 — — 默认:0s;
  6. animation-iteration-count —— 动画播放次数 — — 默认:1次、无限次:infinite;
  7. animation-direction —— 动画下一周期播放方向 — — 默认:normal、逆播放:alternate;
  8. animation-play-state —— 规定动画运行或停止 — — 默认:running、暂停:paused,通常与hover共用;
  9. animation-fill-mode —— 动画结束后状态 — — 默认:backwards、停此处:forwards。
  • 调用速写

(重点)animation : name  duration  timing-function (linear匀速) delay(延迟几秒) iteration-count(循环次数) direction(结束时方向)fill-mode(结束后位置);

  • 典型例子

波点效果

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>月光波点</title>
</head>
<style>
    .container{
        width: 1000px;
        height: 600px;
        background: url(图片地址) no-repeat center/100% 100%;
        position: relative;
    }
    
    .main{
        width: 100px;
        height: 100px;
        position: absolute;
        top: 265px;
        left: 465px;
    }

    .wave{
        width: 43px;
        height: 45px;
        box-shadow: 0 0 12px rgb(146, 155, 168);
        position: absolute;
        right: 50%;
        bottom: 50%;
        transform: translate(50%,50%);
        border-radius: 50%;
        animation: wave 1s infinite;
    }

    .main .a-2{
        animation-delay: 0.3s;
    }

    @keyframes wave {
        0% {}
        70% {
            width: 80px;
            height: 80px;
            opacity: 1;
        }
        100% {
            width: 120px;
            height: 120px;
            opacity: 0;
        }
    }

</style>
<body>
    <div class="container">
        <div class="main">
            <div class="wave a-1"></div>
            <div class="wave a-2"></div>
        </div>
    </div>
    
</body>
</html>

放映图标效果

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>知否放映图标</title>
</head>
<style>
    .container-box{
        height: 300px;
        width: 300px;
        overflow: hidden;
    }
    .box{
        height: 72px;
        width: 150px;
        border:3px solid  rgb(14, 201, 226);
        margin: 100px auto;
        border-radius: 20px;
        position: relative;
        animation: opacity 1s linear  infinite alternate forwards;
    }
    .triangle{
        height: 0;
        width: 0;
        border: solid;
        border-color: rgba(0, 0, 255, 0) rgba(0, 0, 255, 0) white rgba(0, 0, 255, 0);
        border-width: 53px 43px;
        position: absolute;
        right: 50%;
        bottom: -36px;
        transform: translate(50%,0);
        animation: move 1s linear  infinite alternate forwards;
}

    .triangle::after{
        content: "";
        height: 0;
        width: 0;
        border:solid;
        border-color: rgba(0, 0, 255, 0) rgba(0, 0, 255, 0) rgba(23, 201, 224, 0.534) rgba(0, 0, 255, 0);
        border-width: 39px 31px;
        position: absolute;
        right:50%;
        bottom:-45px;
        transform: translate(50%,0);
    }
    @keyframes move {
        0%{

        }
        100%{
            bottom: -18px;
        }
    }

    @keyframes opacity {
        0%{
            background-color: rgba(0, 0, 255, 0);
        }
        100%{
            background-color: rgba(58, 194, 228, 0.377);
        }
    }
</style>
<body>
    <div class="container-box">
        <div class="box">
        <div class="triangle"></div>
        </div>
    </div>
</body>
</html>

打字机及循环移动效果

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>打字机及循环移动效果</title>
</head>
<style>
    .container{
        height: 30px;
        border-radius: 10px;
        border: 1px ridge cadetblue; 
        font-size:20px;
        font-family: 翩翩体-简;
        /* 共15个字,分15步 */
        animation: main 3s steps(15) forwards,move 20s linear 1s infinite alternate;
        overflow: hidden;
    }

    @keyframes main {
        0%{
            width: 0px;
        }
        100%{
            /* 每个字20px,则共需300px。 */
            width: 300px;
        }
    }

    @keyframes move {
        from {
            transform: translate(0,0) rotate(0deg);
        }
        25%{
            transform: translate(1000px,0) rotate(90deg);
        }
        50%{
            transform: translate(1000px, 600px) rotate(180deg);
        }
        75%{
            transform: translate(0,600px) rotate(270deg);
        }
        to{
            transform: translate(0,0) rotate(360deg);
        }
    }

    .container:hover{
        /* 触碰停止效果 */
        animation-play-state: paused;
    }
</style>
<body>
    <div class="container">
        我是图图小淘气,面对世界很好奇
    </div>
</body>
</html>

— — — — 完结

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

march on_6

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值