美文网首页
CSS3 animation动画

CSS3 animation动画

作者: 暴走的金坤酸奶味 | 来源:发表于2018-09-13 11:45 被阅读0次

1、@keyframes 定义关键帧动画
2、animation-name 动画名称
3、animation-duration 动画时间
4、animation-timing-function 动画曲线

linear 匀速
ease 开始和结束慢速
ease-in 开始是慢速
ease-out 结束时慢速
ease-in-out 开始和结束时慢速
steps 动画步数
5、animation-delay 动画延迟
6、animation-iteration-count 动画播放次数 n|infinite
7、animation-direction

normal 默认动画结束不返回
Alternate 动画结束后返回
8、animation-play-state 动画状态

paused 停止
running 运动
9、animation-fill-mode 动画前后的状态

none 不改变默认行为
forwards 当动画完成后,保持最后一个属性值(在最后一个关键帧中定义)
backwards 在 animation-delay 所指定的一段时间内,在动画显示之前,应用开始属性值(在第一个关键帧中定义)
both 向前和向后填充模式都被应用
10、animation:name duration timing-function delay iteration-count direction;同时设置多个属性


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>animation动画</title>
    <style type="text/css">
        .box{
            width: 100px;
            height: 100px;
            background-color: gold;
            /*动画名称、时间、曲线、延迟、播放次数、结束后是否返回、动画前后的状态
            infinite不限制次数
            alternate动画结束后返回,返回也算次数
            animation-fill-mode 动画前后的状态
                forwards动画完成保持在最后一帧
                backwards在延迟时间内,在动画显示之前,应用from开始属性值(例如box宽100,from宽200,在延迟1s内显示200)
                both向前和向后填充模式都被应用(例如起始按200,结束停在最后一帧)
            */
            animation: moving 1s ease 1s 5 alternate both;
            /*动画暂停*/
            /*animation-play-state: paused;*/
        }
        .box:hover{
            /*动画运行*/
            /*animation-play-state: running;*/
        }
        /*定义一个动画,名称为moving*/
        @keyframes moving{
            /*初始状态*/
            from{
                width: 200px;
            }
            /*结束状态*/
            to{
                width: 500px;
            }
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

多帧动画


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>多帧动画</title>
    <style type="text/css">
        .box{
            width: 100px;
            height: 100px;
            background-color: gold;
            margin: 50px auto 0;
            animation: moving 1s ease 1s both;
        }
        @keyframes moving{
            0%{
                /*位移动画*/
                transform: translateY(0px);
                background-color: cyan;
            }
            50%{
                transform: translateY(400px);
                background-color: gold;
                border-radius: 0px;
            }
            100%{
                transform: translateY(0px);
                background-color: red;
                border-radius: 50px;
            }
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

loading动画


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>loading动画</title>
    <style type="text/css">
        .box{
            width: 300px;
            height: 125px;
            border: 1px solid #000;
            margin: 200px auto 0;
        }
        .box p{
            text-align: center;
            width: 100%;

        }
        .box div{
            width: 30px;
            height: 70px;
            float: left;
            background-color: gold;
            margin: 15px;
            border-radius: 10px;
        }
        .box div:nth-child(1){
            background-color: red;
            animation: loading 500ms ease 0s infinite alternate;
        }
        .box div:nth-child(2){
            background-color: green;
            animation: loading 500ms ease 100ms infinite alternate;
        }
        .box div:nth-child(3){
            background-color: pink;
            animation: loading 500ms ease 200ms infinite alternate;
        }
        .box div:nth-child(4){
            background-color: greenyellow;
            animation: loading 500ms ease 300ms infinite alternate;
        }
        .box div:nth-child(5){
            background-color: cyan;
            animation: loading 500ms ease 400ms infinite alternate;
        }
        @keyframes loading{
            from{
                transform: scaleY(1);
            }
            to{
                transform: scaleY(0.5);
            }
        }
    </style>
</head>
<body>
    <div class="box">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <p>loading...</p>
    </div>
</body>
</html>

任务行走


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>人物走路动画</title>
    <style type="text/css">
        .box{
            width: 120px;
            height: 182px;
            /*border: 1px solid black;*/
            margin: 50px auto 0;
            overflow: hidden;
            position: relative;
            animation: moving 2s linear infinite;
        }
        .box img{
            position: absolute;
            left: 0;
            top: 0;
            /*steps动画步数,图片有8帧,所以设置为8步*/
            animation: walking 2s steps(16) infinite;
        }
        @keyframes moving{
            0%{
                transform: translate(0px,0px);/*位移*/
            }
            50%{
                transform: translate(200px,0px);
            }
            100%{
                transform: translate(0px,0px);
            }
        }
        @keyframes walking{
            from{
                left: 0px;
            }
            to{
                left: -1920px;
            }
        }
    </style>
</head>
<body>
    <div class="box">
        <img src="img/walking1.png" alt="人物走路">
    </div>
</body>
</html>
walking.png

相关文章

  • 网页高级知识点(三)

    CSS3 transition动画 CSS3 transform变换 CSS3 animation动画

  • 2017-06-18

    css3中变形与动画(上) 1.Animation 动画定义animation动画2.Animation动画播放 ...

  • CSS3 animation动画

    CSS3 animation动画 1、@keyframes 定义关键帧动画2、animation-name 动画名...

  • 前端知识CSS3 animation动画

    CSS3 animation动画 1、@keyframes 定义关键帧动画2、animation-name 动画名...

  • html(入门)CSS3 animation动画

    CSS3 animation动画 1、@keyframes 定义关键帧动画2、animation-name 动画名...

  • CSS3- animation-动画基础篇

    CSS3动画 -- animation相关属性 1 animation-name: 动画名 指定应用一系列的动画,...

  • CSS3 动画

    动画属性 动画(animation)是CSS3新增的属性,动画属性可以为元素创建动画,CSS3以前在网页上实现动画...

  • 实现动画的6种方案

    通常,前端实现动画的方案主要有6种:CSS3 transition、CSS3 animation、Canvas动画...

  • 2018-06-13

    Css动画: css3动画主要包括Transform、Transition、Animation 区别 transi...

  • H5动画效果

    我们使用CSS3可以实现动画,主要的方式是通过animation 实现的。 animation属性 animati...

网友评论

      本文标题:CSS3 animation动画

      本文链接:https://www.haomeiwen.com/subject/dqlwgftx.html