CSS 动画收集

Clloz · · 484次浏览 ·

前言

对于 CSS 的动画又很多种方式来实现,又 trasformtransition 的配合,也有为扩展 transition 的新属性 animation。有了这些属性,让页面的动画效果有了无限可能。我自己对于动画的运用还属于非常初级的阶段,所以用这篇文章来收集一些有趣的动画特效,看看别人是怎么实现的,来积累一些 CSS 动画的经验。

月亮圆缺动画

<div class="track">
  <div class="moon"></div>
</div>
* {
    margin: 0;
    padding: 0;
}
body {
    background: black;
}
.track {
    width: 100px;
    height: 100px;
    margin: 0 auto;
    animation: circle 5s linear infinite;
    transform-origin: 50% 400px;
}
.moon {
    width: 100px;
    height: 100px;
    background: white;
    border-radius: 50%;
    position: relative;
    animation: inner-circle 5s linear infinite;
}

.moon:before {
    content: "";
    display: block;
    position: absolute;
    background: black;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    top: 0;
    left: 0;
    animation: x 5s linear infinite;
}

.moon:after {
    content: "";
    display: block;
    position: absolute;
    background: black;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    top: 0;
    left: 0;
    animation: y 5s linear infinite;
}

@keyframes x {
    0% {
        transform: translate(-0%, -0%);
    }
    50% {
        transform: translate(-80%, -80%);
    }
    100% {
        transform: translate(-80%, -80%);
    }
}

@keyframes y {
    0% {
        transform: translate(80%, 80%);
    }
    50% {
        transform: translate(80%, 80%);
    }
    100% {
        transform: translate(0%, 0%);
    }
}

@keyframes circle {
    from {
        transform: rotate(-90deg);
    }
    to {
        transform: rotate(90deg);
    }
}

@keyframes inner-circle {
    from {
        transform: rotate(90deg);
    }
    to {
        transform: rotate(-90deg);
    }
}

代码地址:moon

方块 loading

<div class="square-loading"></div>
.square-loading {
    position: absolute;
    width: 50px;
    height: 50px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.square-loading::before {
    content: "";
    position: absolute;
    width: 50px;
    height: 5px;
    background: #000;
    opacity: 0.1;
    border-radius: 50%;
    top: 59px;
    animation: shadow 0.5s infinite linear;
}

.square-loading::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 50px;
    height: 50px;
    background: #ccc;
    border-radius: 3px;
    animation: animate 0.5s infinite linear;
}

@keyframes shadow {
    0%,
    100% {
        transform: scale(1, 1);
    }

    50% {
        transform: scale(1.2, 1);
    }
}

@keyframes animate {
    17% {
        border-bottom-right-radius: 3px;
    }

    25% {
        transform: translateY(9px) rotate(22.5deg);
    }

    50% {
        transform: translateY(18px) scale(1, 0.9) rotate(45deg);
        border-bottom-right-radius: 40px;
    }

    75% {
        transform: translateY(9px) rotate(67.5deg);
    }

    100% {
        transform: translateY(0) rotate(90deg);
    }
}

代码地址:方块Loading

水波效果

<div class="container">
    <div class="card">
        <div class="wave w1"></div>
        <div class="wave w2"></div>
        <div class="wave w3"></div>
    </div>
</div>
html {
    height: 100vh;
}
body {
    height: inherit;
    background: #2e576b;
    display: -ms-grid;
    display: grid;
}
.container {
    margin: auto;
}
.card {
    position: relative;
    width: 300px;
    height: 350px;
    background: #fff;
    border-radius: 2px;
    box-shadow: 0 2px 15px 3px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}
.card::after {
    content: "";
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        to bottom,
        #0065a8,
        rgba(221, 238, 255, 0.4) 46%,
        rgba(255, 255, 255, 0.5)
    );
}
.wave {
    position: absolute;
    top: 3%;
    left: 50%;
    width: 400px;
    height: 400px;
    margin-top: -200px;
    margin-left: -200px;
    background: #0af;
    border-radius: 40%;
    opacity: 0.4;
    animation: shift 3s infinite linear;
}
.wave.w2 {
    background: yellow;
    opacity: 0.1;
    animation: shift 7s infinite linear;
}
.wave.w3 {
    animation: shift 5s infinite linear;
    background: crimson;
    opacity: 0.1;
}
@-webkit-keyframes shift {
    from {
        transform: rotate(360deg);
    }
}
@keyframes shift {
    from {
        transform: rotate(360deg);
    }
}

代码地址:水波效果


Clloz

人生をやり直す

发表评论

电子邮件地址不会被公开。 必填项已用*标注

我不是机器人*

 出现新的回复时用邮件提醒我。

EA PLAYER &

历史记录 [ 注意:部分数据仅限于当前浏览器 ]清空

      00:00/00:00