CSS动画实用技巧

1.设置animation-delay为负值

定义动画何时开始,默认为0,即立即执行,设置为负值为立即执行,但跳过指定时间后进入动画。
设置animation-delay为负值,可以让动画立即执行,而且可以精准控制动画开始在哪个阶段。

<div class="load">
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
    </div>
/*加载动画效果*/
.load{
    width: 70px;
    height: 50px;
    margin: 100px auto;
}

.load .item{
    display: inline-block;
    height: 100%;
    width: 10px;
    background-color: green;
    animation: load-item 1s infinite ease-in-out;
    transform-origin: center bottom;
}

.load .item:nth-child(2){
    animation-delay: -0.8s;
}

.load .item:nth-child(3){
    animation-delay: -0.6s;
}

.load .item:nth-child(4){
    animation-delay: -0.4s;
}

.load .item:nth-child(5){
    animation-delay: -0.2s;
}

@keyframes load-item{
    0%,40%,100%{
        transform: scaleY(0.6);
    }

    20%{
        transform: scaleY(1);
    }
}

这样就可以控制每个条纹开始动画的阶段,达到按顺序执行的效果。

2.使用border颜色

元素的边框由四部分组成,可以改变其中几个部分的颜色,再将元素旋转起来,用来制作加载动画

<div class="circle"></div>
/*圆形加载效果*/
.circle{
    width: 200px;
    height: 200px;
    margin: 100px auto;
    box-sizing: border-box;
    border: 15px solid #ccc;
    border-left-color: #fff;
    border-radius: 50%;
    animation: circle 1s linear infinite;
}

@keyframes circle{
    from{
        transform: rotate(0);
    }

    to{
        transform: rotate(360deg);
    }
}

3.使用border-width宽度

使用border-width宽度过渡,可以创建出图片的折角动画,再配合opacity可以使图片翻页。

<div class="book">
    ![](banner1.jpg)
</div>
.book{
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;
    cursor: pointer;
    opacity: 1;
    transition: all 500ms;
}

.book img{
    transition: all 500ms;
    border-radius: 4px;
}

.book:before{
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    border-style: solid;
    border-width: 0;
    border-color: rgba(0,0,0,0.2) #fff;
    border-radius: 0 0 0 4px;
    transition: all 500ms;
}

.book:hover::before{
    border-right-width: 40px;
    border-bottom-width: 40px;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 2,413评论 0 11
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    wzhiq896阅读 2,077评论 0 2
  • 1.CSS3 边框 border-radius CSS属性用来设置边框圆角。当使用一个半径时确定一个圆形;当使用两...
    garble阅读 768评论 0 0
  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 14,034评论 1 92
  • 1、属性选择器:id选择器 # 通过id 来选择类名选择器 . 通过类名来选择属性选择器 ...
    Yuann阅读 1,745评论 0 7

友情链接更多精彩内容