CSS Day11- 动画

11.1 动画语法
<!DOCTYPE html>
<html lang="en">
​
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
            /* 动画名 */
            animation-name: yidong;
            /* 设置动画时间 */
            animation-duration: 3s;
            /* 设置延迟时间 */
            animation-delay: 0.2s;
        }
​
        @keyframes yidong {
​
            /* 第一种写法:from to */
            /* from {
                background-color: red;
            }
​
            to {
                transform: translate(500px);
                background-color: skyblue;
            } */
            
            /* 第二种写法:使用百分比进行设置 */
            0%{
                background-color: green;
            }
            40%{
                background-color: red;
                transform: translateY(700px);
            }
            80%{
                background-color: yellow;
                transform: translate(200px,400px);
            }
            100%{
                background-color: pink;
                transform: translate(400px,500px);
            }
        }
​
    </style>
</head>
​
<body>
    <div></div>
</body>
​
</html>
  • 设置动画的类型 animation-timing-function: linear; ease 默认值 平滑动画 linear 线性过渡 ease-in 从慢到快 ease-out 从快到慢 ease-in-out 慢 快 慢 steps 分步执行

  • 设置动画的执行次数 animation-iteration-count: 1; 参数值可以是数字 infinite 无限次循环(常用)

  • 动画执行的方式 animation-direction: alternate-reverse; normal 默认值 从from到to运行,每次都是这样 reverse 从to到from运行,每次都是这样 alternate 从from到to运行,重复执行时动画会反向执行 alternate-reverse 从to到from运行,重复执行时动画反向执行

  • 动画填充模式 animation-fill-mode: backwards; none 默认值 动画执行完毕0,回到原来的位置 forwards 动画执行完毕时,会停留在动画结束的位置 backwards 动画执行完毕时,回到开始的位置

11.2 过渡

过渡和动画类似,动画是页面一加载就直接执行的属性,过渡是必须有触发条件才会执行

.box {
            width: 100px;
            height: 100px;
            background-color: pink;
            /*opacity: 0;*/   /* 不透明度 */
            /* 动画和过渡相似,动画是页面一加载就直接执行的属性,过渡是必须有触发条件才会执行 */
​
            /* 第一步 设置哪个属性需要过渡效果 
             transition-property 设置需要过渡的属性,属性之间用逗号(,)隔开
                 all代表所有需要过渡的属性
            */
            /* transition-property: height, width, background-color, opacity; */
            transition-property: all;
            /* 设置过渡时间 */
            transition-duration: 1s;
        }
​
        .box:hover {
            height: 200px;
            width: 200px;
            background-color: orange;
            opacity: 1;
        }
  • transition-timing-function 过渡的类型

    ease默认值 平滑过渡

    ease-in 先慢后快

    ease-out 先快后慢

    steps()分布执行过渡效果

    可以设置一个第二个值

    end,在时间结束时执行过渡(默认值)

    start,在时间开始时执行过渡

  • 15
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值