CSS 动画收集

栏目: CSS · 发布时间: 4年前

内容简介:对于代码地址:moon代码地址:方块Loading

前言

对于 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);
    }
}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

马尔可夫链:模型、算法与应用

马尔可夫链:模型、算法与应用

Wai-Ki Ching、Ximin Huang / 陈曦 / 清华大学出版社 / 2015-6 / 39

《马尔可夫链:模型、算法与应用 应用数学译丛》讲述了马尔可夫链模型在排队系统、网页重要性排名、制造系统、再制造系统、库存系统以及金融风险管理等方面的最新应用进展.全书共安排8章内容,第1章介绍马尔可夫链、隐马尔可夫模型和马尔可夫决策过程的基本理论和方法,其余7章分别介绍马尔可夫链模型在不同领域中的应用. 《马尔可夫链:模型、算法与应用 应用数学译丛》可作为自动化、工业工程、统计学、应用数学以及管理......一起来看看 《马尔可夫链:模型、算法与应用》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具