Html+Css小tips:动画

动画和过渡类似,都是可以实现一些动态的效果,
不同的是过渡需要在某个属性的发生变化时触发
动画可以自动出发动态效果

设置动画效果,必须要先设置一个关键帧,关键帧就设置了动画执行的每一个步骤

<!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;
        }
        .box1{
            width: 800px;
            height: 800px;
            background-color: #fff;
            overflow: hidden;
        }
        .box1 div{
            width: 100px;
            height: 100px;
            margin-bottom: 100px;
            margin-left: 0;
        }

        .box2{
            background-color:blue;
            /* 设置box2的动画效果 */
            /* animation-name 要对当前元素生效的关键帧的名字*/
            animation-name: test;

            /*animation-duration 动画的执行时间  */
            animation-duration : 5s;

            /* animation-delay: 动画延时 */
            animation-delay: 2s;

            /* animation-timing-function 动画运动样式  */
            animation-timing-function: ease-in-out;

            /* animation-iteration-count 动画执行次数 */
            animation-iteration-count: infinite;
        }

        @keyframes test{

            /*  表from示动画结束的位置 也可以使用 0% */ 
            from{
                margin-left: 0px;
            }
            /* to 表示动画结束的位置 也可以使用 100% */
            to{
                margin-left: 700px;
            }
        }


    </style>
</head>
<body>
    <div class="box1">
        <div class="box2"></div>
    </div>
</body>
</html>

执行状态

animation-play-state: paused;
设置动画的执行状态
可选值:
running 默认值 动画执行
paused 动画暂停

填充模式

animation-fill-mode: both;
动画的填充模式
可选值:
none (默认值 动画执行完毕元素回到原来位置)
forwards (动画执行完毕元素会停止在动画结束的位置)
backwards (动画延时等待时,元素会处于开始位置)
both (结合了forwards和backwards)

简写:
            animation: test 2s 1s alternate;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值