内容简介:对于代码地址:moon代码地址:方块Loading
前言
对于 CSS
的动画又很多种方式来实现,又 trasform
和 transition
的配合,也有为扩展 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);
}
}
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
JavaScript实战手册
David Sawyer McFarland / 李强 / 机械工业出版社 / 2009 / 89.00元
在《JavaScript实战手册》中,畅销书作者David McFarland教你如何以高级的方式使用JavaScript,即便你只有很少或者没有编程经验。一旦掌握了这种语言的结构和术语,你将学习如何使用高级的JavaScript工具来快速为站点添加有用的交互,而不是一切从头开始编写脚本。和其他的Missing Manuals图书不同,《JavaScript实战手册》清楚、精炼,手把手地讲解。 ......一起来看看 《JavaScript实战手册》 这本书的介绍吧!