CSS 动画收集

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

内容简介:对于代码地址: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);
    }
}

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

查看所有标签

猜你喜欢:

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

裂变式创业

裂变式创业

宗毅、小泽 / 机械工业出版社 / 2016-1-1 / 39.84

互联网大潮汹涌来袭,传统企业增长乏力,互联网公司跨界冲击,转型之路迫在眉睫。“转型找死,不转型等死”这一坊间传说让多数企业徘徊不前,不少实体经济面临困境,敢问路在何方? 宗毅独创裂变式创业,用人民币投票选总经理,规定自己不投钱不能参与竞选;不相信干股,不使用职业经理人,用金融的方式管理现金流。用商业模式颠覆传统公益,打通南北充电之路;摇身一变成为自媒体,用产品建立社群。自己写故事,自己当导演......一起来看看 《裂变式创业》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

SHA 加密
SHA 加密

SHA 加密工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换