CSS3动漫之DIY Loading动漫

2021-01-20 18:18 jianzhan

最先要了解甚么是CSS3动漫?随后才可以做出自身要想的动漫实际效果。下面会根据3个简易的Loading动漫实际效果来对CSS3 animation动漫做1个简易详细介绍,期待对你有效。

动漫是使元素从1种款式慢慢转变为另外一种款式的实际效果。

您能够更改随意多的款式随意多的次数。

应用百分比来要求转变产生的時间,或用重要词 "from" 和 "to",等同于于 0% 和 100%。

0% 是动漫的刚开始,100% 是动漫的进行。

要建立CSS3动漫,那末最先就要掌握@keyframes标准。@keyframes标准是建立动漫。 @keyframes标准内特定1个CSS款式和动漫将逐渐从现阶段的款式变更为新的款式。

当在 @keyframes 建立动漫,把它关联到1个挑选器,不然动漫不容易有任何实际效果。

特定最少这两个CSS3的动漫特性关联向1个挑选器:要求动漫的名字;要求动漫的时长。

css3动漫特性

Loading动漫1:

点.gif

<!-- html编码 一共8个点 -->
 <div class="point-loading">
        <span class="point"></span>
        <span class="point"></span>
        <span class="point"></span>
        <span class="point"></span>
        <span class="point"></span>
        <span class="point"></span>
        <span class="point"></span>
        <span class="point"></span>
    </div>
/*css款式编码*/
/*界定动漫*/
@keyframes pointLoading {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(.3);
        opacity: 0.5;
    }
}
/*界定款式*/
.point-loading {
    width: 100px;
    height: 100px;
    position: relative;
    margin: 0 auto;
    margin-top: 150px;
    margin-bottom: 100px;
}
.point-loading .point {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: lightgreen;
    position: absolute;
    animation-name:pointLoading;   /*关联动漫*/
    animation-duration:1s; /*关联动漫进行1个周期所用時间*/
    animation-iteration-count:infinite; /*动漫播发次数  默认设置是1,infinite无尽次播发*/
}
/*nth-child:挑选器配对属于其父元素的第 N 个子元素;animation-delay:动漫延迟时间播发*/
.point-loading .point:nth-child(1) {
    left: 0;
    top: 50%;
    margin-top: ⑴0px;
    animation-delay: 0.13s;
}
.point-loading .point:nth-child(2) {
    left: 14px;
    top: 14px;
    animation-delay: 0.26s;
}
.point-loading .point:nth-child(3) {
    left: 50%;
    top: 0;
    margin-left: ⑴0px;
    animation-delay: 0.39s;
}
.point-loading .point:nth-child(4) {
    top: 14px;
    right: 14px;
    animation-delay: 0.52s;
}
.point-loading .point:nth-child(5) {
    right: 0;
    top: 50%;
    margin-top: ⑴0px;
    animation-delay: 0.65s;
}
.point-loading .point:nth-child(6) {
    right: 14px;
    bottom: 14px;
    animation-delay: 0.78s;
}
.point-loading .point:nth-child(7) {
    bottom: 0;
    left: 50%;
    margin-left: ⑴0px;
    animation-delay: 0.91s;
}
.point-loading .point:nth-child(8) {
    bottom: 14px;
    left: 14px;
    animation-delay: 1.04s;
}

Loading动漫2:

圆环.gif

 <!-- html编码 -->
<div class="loading"></div>
/*css编码*/
/*最先是界定动漫实际效果*/
@keyframes rotateLoading {
    from {
        transform:rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}
/*界定基础款式,关联动漫,界定动漫特性*/
.loading {
    margin: 50px auto;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 10px solid  rgba(0, 0, 0, 0.2);
    border-top-color: #000;
    position: relative;
    animation-name: rotateLoading;
    animation-timing-function: linear;
    animation-duration: 1.1s;
    animation-iteration-count: infinite;
}

Loading动漫3:

柱状.gif

<!--html编码 共5个柱状 -->
 <div class="pillar-loading">
        <span class="pillar"></span>
        <span class="pillar"></span>
        <span class="pillar"></span>
        <span class="pillar"></span>
        <span class="pillar"></span>
    </div>
/*css编码*/
@keyframes pillarLoading {
    0%,
    100% {
        background: lightgreen;
    }
    50% {
        transform: scaleY(1.75);
        background: lightblue;
    }
}

.pillar-loading {
    margin: 150px auto;
    width: 60px;
    display: flex;
    justify-content: space-between;
}
.pillar-loading .pillar {
    width: 8px;
    height: 40px;
    border-radius: 4px;
    background: lightgreen;
    animation-name: pillarLoading;
    animation-iteration-count: infinite;
    animation-duration: 1s;
    animation-timing-function: ease;
}
.pillar-loading .pillar:nth-child(2){
    animation-delay: 0.2s;
}
.pillar-loading .pillar:nth-child(3){
    animation-delay: 0.4s;
}
.pillar-loading .pillar:nth-child(4){
    animation-delay: 0.6s;
}
.pillar-loading .pillar:nth-child(5){
    animation-delay: 0.8s;
}

以上3个动漫是Animation动漫的简易示例。

下面再说1个动漫必备特性 transform。

transform 原意是形变,转换之意,在 CSS 中应用该特性可对元素开展挪动(translate)、转动(rotate)、放缩(scale)、歪斜(skew)等实际效果。因其拥有各种各样殊效及优质的特性,因此变成动漫的标配。

** 变换方式**

transform变换方式

1个简易的小球动漫,电脑鼠标移到小球上或空白框内,小球刚开始做动漫,电脑鼠标移出,动漫终止。

小球动漫

 <!-- html编码 -->
<div class="box">
        <div class="circle"></div>
    </div>
.box {
          width: 600px;
          height: 200px;
          border: 1px solid #ccc;
          background: #fff;
          margin: 50px,auto
}
.circle {
            width: 50px;
            height: 50px;
            background: blue;
            border-radius: 50%;
            margin: 75px,0;
            transition: all 2s   /*2s进行*/
}
.box:hover .circle {
           background: red;
           transform: translate(550px,0)   /*沿x轴偏位550px*/
}

再来1个略微难1点的。

transform动漫

<!-- html编码 -->
<a href="https://y.qq.com/n/yqq/album/002JRl3m16wLPL.html" class="playlist-item">
        <div class="item-bd">
            <img class="item-img" src="http://coding.imweb.io/img/p3/transition-hover.jpg" alt="">
            <i class="icon-play"></i>
        </div>
        <div class="item-ft">
            <h3 class="item-tt">漂洋过海看来你 OST 原声辑</h3>
            <p class="item-author">严艺丹</p>
        </div>
    </a>
/*css款式编码*/
.playlist-item {
    display: block;
    margin-top: 100px;
    width: 300px;
    background: rgba(0, 0, 0, .6);
}
.playlist-item:hover {
    background: #31c27c;
}

.playlist-item .item-bd {
    overflow: hidden;
    position: relative;
}
.playlist-item .item-img {
    width: 100%;
    transition:all 0.75s;
}
.playlist-item .icon-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(⑸0%, ⑸0%) scale(.7);
    width: 70px;
    height: 70px;
    background: url(http://coding.imweb.io/img/p3/transition-cover_play.png) no-repeat;
    opacity: 0;
}
.playlist-item .item-bd:hover .item-img {
    transform:scale(1.1);
}
.playlist-item .item-bd:hover .icon-play {
    opacity: 0.8;
    transform: translate(⑸0%, ⑸0%) scale(1);
}
.playlist-item .item-ft {
    color: #fff;
    padding: 15px 10px;
    text-align: center;
}
.playlist-item .item-tt {
    font-size: 16px;
    position: relative;
    display: inline-block;
    vertical-align: middle;
}
.playlist-item .item-tt::after {
    content: "...";
    width: 18px;
    height: 18px;
    font-size: 12px;
    color: #fff;
    border-radius: 50%;
    border: 2px solid #fff;
    position: absolute;
    right: ⑵5px;
    top: 50%;
    transform: translate(0, ⑸0%);
    line-height: 0.6;
    box-sizing: border-box;
    opacity: 0;
    transition:all 0.75s;
}
.playlist-item .item-author {
    color: #999;
}
.playlist-item:hover .item-author {
    color: #c1e9d5;
}
.playlist-item:hover .item-tt::after {
    opacity:1;
}

以上便是本文的所有內容,期待对大伙儿的学习培训有一定的协助,也期待大伙儿多多适用脚本制作之家。