CSS 动画例子

2018-08-01  本文已影响20人  白雪公主960

html中

<div id="d1"></div>

css中

/*声明动画*/
@keyframes scroll{
    0%{
        /*宽度,高度,背景颜色*/
        width:100px;
        height:100px;
        background:red;
    }
    25%{
        /*倒角,左外边距,背景颜色*/
        border-radius:50%;
        margin-left:200px;
        margin-top:0px;
        background:yellow;
    }
    50%{
        /*倒角,左外边距,上外边距,背景颜色*/
        border-radius:50%;
        margin-left:200px;
        margin-top:200px;
        background:blue;
    }
    75%{
        border-radius:50%;
        margin-left:0px;
        margin-top:200px;
        background:green;
    }
    100%{
        border-radius:0px;
        margin-top:0px;
        background:red;
    }
}

#d1{
    width:100px;
    height:100px;
    /*页面加载时,就实现动画效果*/
    animation-name:scroll; //动画名称
    animation-duration:5s; //动画时长
    animation-timing-function:linear; //动画速度时间曲线函数:
    animation-delay:5s; //动画延迟时间:5秒
    animation-iteration-count:infinite;//动画播放次数:无限循环
    animation-direction:alternate; //动画播放方向:奇数播放次数是正向播放,偶数播放次数时,逆向播放
    animation-fill-mode:both;//规定动画在播放之前或之后,动画效果是否可见:动画播放前后都采用填充模式
}
#d1:hover{
    animation-play-state:paused; // 规定动画的播放状态(运行或暂停)
}

以下是运行动图,会有5秒的延迟时间哦


初始样子:



25%时:



50%时:

75%:


注:

上一篇 下一篇

猜你喜欢

热点阅读