animation动画

animation动画基础语法

animation-name 规定需要绑定到选择器的 keyframe 名称。。
animation-duration 规定完成动画所花费的时间,以秒或毫秒计。默认值:0
animation-delay 规定在动画开始之前的延迟。值单位可以是秒(s)或毫秒(ms)。默认值: 0,提示: 允许负值,-2s 使动画马上开始,但跳过 2 秒进入动画。
animation-iteration-count 规定动画应该播放的次数。默认值:1
在这里插入图片描述

animation-timing-function 规定动画的速度曲线。默认值:ease

animation-timing-function: linear|ease|ease-in|ease-out|cubic-bezier(n,n,n,n);

在这里插入图片描述

animation-direction 规定是否应该轮流反向播放动画。默认值:normal如果把动画设置为只播放一次,则该属性没有效果。

animation-direction: normal|reverse|alternate|alternate-reverse;

在这里插入图片描述

复合写法,顺序是上面介绍顺序

.box2{width: 100px;height: 100px;background: red;animation: myBox 4s 2s infinite linear;}

等价于

       .box2{width: 100px;height: 100px;background: red;
              animation-name: myBox;
              animation-duration: 4s;
              animation-delay: 2s;/*如果是-2秒,则只执行一半过程 */
              animation-iteration-count: 3;}

综合

<!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>Document</title>
    <style>
        .box1{width: 300px;height: 300px;border: 1px black solid;margin: 30px auto;}
        .box2{width: 100px;height: 100px;background: red;
              animation-name: myBox;
              animation-duration: 4s;
              animation-delay: 2s;/*如果是-2秒,则只执行一半过程 */
              animation-iteration-count: 3;}
              /* 第二种复合写法 */
              /* .box2{width: 100px;height: 100px;background: red;animation: myBox 4s 2s infinite linear;} */
              /* infinite意思是次数无数次 */
              @keyframes myBox{
                  0%{transform: translate(0,0);}
                  25%{transform: translate(200px,0);}
                  50%{transform: translate(200px,200px);}
                  75%{transform: translate(0,200px);}
                  100%{transform: translate(0,0);}
              }
    </style>
</head>
<body>
    <div class="box1">
        <div class="box2"></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>Document</title>
    <style>
        *{margin: 0;padding: 0;}
        ul{list-style: none;}
        ul{width: 600px;margin: 30px auto;}
        ul li{float: left;width: 100px;height: 100px;position: relative;}
        ul li img{position: absolute;}
        ul li:hover img{animation: move .5s;}
        @keyframes move{
            0%{transform: translate(0,0);opacity: 1;}
            60%{transform: translate(0,-100px);opacity: 0;}
            61%{transform: translate(0,100px);}
            100%{transform: translate(0,0);opacity: 1;}
        }
    </style>
</head>
<body>
    <ul>
        <li>
            <img src="https://p2.ssl.qhimgs1.com/sdr/400__/t01948d3af3a434ed22.jpg" alt="">
        </li>
    </ul>
</body>
</html>

在这里插入图片描述

loading加载动画效果

loading加载动画效果

<!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>loading加载动画效果</title>
    <style>
        .loading{width: 40px;height: 40px;margin: 30px auto;position: relative;}
        .loading .box1, .loading .box2{width: 100%;height: 100%;position: absolute;}
        .loading .box2{transform: rotate(45deg);}
        .loading .box1 div, .loading .box2 div{width: 10px;height: 10px;background: blue;border-radius: 50%;position: absolute;animation: loadingMove 1.5s infinite linear;}
         .loading .box1 div:nth-child(1), .loading .box2 div:nth-child(1){left: 0;top: 0;}
         .loading .box1 div:nth-child(2), .loading .box2 div:nth-child(2){right: 0;top: 0;}
         .loading .box1 div:nth-child(3), .loading .box2 div:nth-child(3){right: 0;bottom: 0;}
         .loading .box1 div:nth-child(4), .loading .box2 div:nth-child(4){left: 0;bottom: 0;}
         @keyframes loadingMove{
             0%{transform: scale(1);}
             50%{transform: scale(0);}
             100%{transform: scale(1);}
         }
         .loading .box1 div:nth-child(1){animation-delay: 0;}
         .loading .box2 div:nth-child(1){animation-delay: .2s;}
         .loading .box1 div:nth-child(2){animation-delay: .4s;}
         .loading .box2 div:nth-child(2){animation-delay: .6s;}
         .loading .box1 div:nth-child(3){animation-delay: .8s;}
         .loading .box2 div:nth-child(3){animation-delay: 1s;}
         .loading .box1 div:nth-child(4){animation-delay: 1.2s;}
         .loading .box2 div:nth-child(4){animation-delay: 1.4s;}
    </style>
</head>
<body>
    <div class="loading">
    <div class="box1">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
    </div>
    <div class="box2">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
    </div>
    </div>
</body>
</html>

在这里插入图片描述

animation动画扩展语法

animation-fill-mode:规定动画 播放之前或之后,其动画效果是否可见。
注释:其属性值是由逗号分隔的一个或多个填充模式关键词。默认值: none在运动结束之后回到初始位置,在延迟的情况下,让0%在延迟后生效。
backwards在延迟的情况下,让0%在延迟前生效
forwards在运动结束之后,停到结束的位置
both:backwards和forwards同时生效

<!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>Document</title>
    <style>
        .box1,.box2,.box3,.box4{width: 100px;height: 100px;background: red;margin: 5px;}
        .box1{animation: 2s move 2s;}
        .box2{animation: 2s move 2s;animation-fill-mode: backwards;}
        .box3{animation: 2s move 2s;animation-fill-mode: forwards;}
        .box4{animation: 2s move 2s;animation-fill-mode: both;}
        @keyframes move{
            0%{transform: translate(0,0);background: blue;}
            100%{transform: translate(300px,0);}
        }
    </style>
</head>
<body>
    <div class="box1">1</div>
    <div class="box2">2</div>
    <div class="box3">3</div>
    <div class="box4">4</div>
</body>
</html>

开始前:
在这里插入图片描述
结束后:
在这里插入图片描述
**animation-direction:**属性定义是否应该轮流反向播放动画
alternate一次正向(0%----100%)一次反向(100%—0%)
reverse永远都是反向,从100%—0%
normal(默认值)永远都是正向,从0%—100%

<!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>Document</title>
    <style>
        div{width: 100px;height: 100px;background: red;
            animation: 1s move infinite;animation-direction: alternate;}
            @keyframes move{
                0%{transform: translate(0,0);}
                100%{transform: translate(300px,0);}
            }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

效果途中
在这里插入图片描述

animate.css动画库

animate.css动画库
官网地址:https://daneden.github.io/animate.css/
基本使用:
animated基类(基础的样式,每个动画效果都需要加)
infinite动画的无限次数
请添加图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值