放上做的两个小的css3动画,先附上简单的静态图:
以下是我的github上的动画效果
高级立方体:
yangyufei.github.io/css3/html/%…
幸福摩天轮:
yangyufei.github.io/css3/html/%…
高级立方体代码如下:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>CSS3高级立方体</title>
<style>
.wrap {
width: 200px;
margin: 0 auto;
/*设置视角*/
-webkit-perspective: 800;
-webkit-transition: all 1s linear;
/*如果不设置默认为无限远的距离,设置不同的视角大小,指的是距离物体的px值。将视角设置不同的层级上面也会有不同的效果*/
}
.cube {
position: relative;
width: 200px;
height: 200px;
margin: 200px auto 0;
-webkit-transform-style: preserve-3d;
/*-webkit-transform: rotateX(30deg) rotateY(75deg);*/
-webkit-animation: bg-change 3s linear infinite;
/*通常是放在父级 将变形的样式设置为3d样式*/
}
.wrap:hover .cube div:nth-child(1){
-webkit-transform: translateZ(200px);
}
.wrap:hover .cube div:nth-child(2){
-webkit-transform: rotateY(180deg) translateZ(200px);
}
.wrap:hover .cube div:nth-child(3){
-webkit-transform: rotateY(90deg) translateZ(200px);
}
.wrap:hover .cube div:nth-child(4){
-webkit-transform: rotateY(-90deg) translateZ(200px);
}
.wrap:hover .cube div:nth-child(5){
-webkit-transform: rotateX(90deg) translateZ(200px);
}
.wrap:hover .cube div:nth-child(6){
-webkit-transform: rotateX(-90deg) translateZ(200px);
}
.cube div {
position: absolute;
left: 0;
top: 0;
width: 200px;
height: 200px;
/*-webkit-backface-visibility: hidden; *//*背部隐藏,解决透视效果*/
}
@-webkit-keyframes bg-change {
from {
-webkit-transform: rotateX(0deg) rotateY(0deg);
}
to {
-webkit-transform: rotateX(360deg) rotateY(360deg);
}
}
/*前后面*/
.cube div:nth-child(1){
background: url(../images/1.png) center center no-repeat;
background-size: contain;
-webkit-transform: translateZ(100px);
-webkit-transition: all 1s linear;
}
.cube div:nth-child(2){
background: url(../images/2.png) center center no-repeat;
background-size: contain;
-webkit-transform: rotateY(180deg) translateZ(100px);
-webkit-transition: all 1s linear;
}
/*左右面*/
.cube div:nth-child(3){
background: url(../images/3.png) center center no-repeat;
background-size: contain;
-webkit-transform: rotateY(90deg) translateZ(100px);
-webkit-transition: all 1s linear;
}
.cube div:nth-child(4){
background: url(../images/4.png) center center no-repeat;
background-size: contain;
-webkit-transform: rotateY(-90deg) translateZ(100px);
-webkit-transition: all 1s linear;
}
/*上下面*/
.cube div:nth-child(5){
background: url(../images/5.png) center center no-repeat;
background-size: contain;
-webkit-transform: rotateX(90deg) translateZ(100px);
-webkit-transition: all 1s linear;
}
.cube div:nth-child(6){
background: url(../images/6.png) center center no-repeat;
background-size: contain;
-webkit-transform: rotateX(-90deg) translateZ(100px);
-webkit-transition: all 1s linear;
}
</style>
</head>
<body>
<div class="wrap">
<div class="cube">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
</div>
<script></script>
</body>
</html>复制代码
幸福摩天轮代码如下:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>CSS3幸福摩天轮</title>
<style>
body,html {
width: 100%;
height: 100%;
}
.wrap {
height: 100%;
background: url(../images/2.jpg) center center no-repeat;
}
.con {
position: relative;
width: 600px;
height: 600px;
margin: 0 auto;
-webkit-transform-style: preserve-3d;
}
.outer {
position: relative;
z-index: 1;
width: 600px;
height: 600px;
background: url("../images/fsw.png") center center no-repeat;
background-size: contain;
-webkit-animation: bg-change 6s linear infinite;
}
@-webkit-keyframes bg-change {
0% {
-webkit-transform: rotateZ(0deg);
}
100% {
-webkit-transform: rotateZ(360deg);
}
}
.font {
position: absolute;
z-index: 2;
top: 150px;
left: 100px;
width: 400px;
height: 250px;
background: url("../images/big-title.png") center center no-repeat;
background-size: contain;
}
.outer div {
width: 100px;
height: 100px;
}
.outer div:nth-child(1) {
position: absolute;
z-index: 1;
top: 0px;
left: 250px;
background: url(../images/dog.png) center center no-repeat;
background-size: contain;
-webkit-animation: rot 6s linear infinite;
}
.outer div:nth-child(2) {
position: absolute;
z-index: 1;
top: 100px;
left: 440px;
background: url(../images/girl.png) center center no-repeat;
background-size: contain;
-webkit-animation: rot 6s linear infinite;
}
.outer div:nth-child(3) {
position: absolute;
z-index: 1;
top: 280px;
left: 530px;
background: url(../images/boy.png) center center no-repeat;
background-size: contain;
-webkit-animation: rot 6s linear infinite;
}
.outer div:nth-child(4) {
position: absolute;
z-index: 1;
top: 480px;
left: 450px;
background: url(../images/girls.png) center center no-repeat;
background-size: contain;
-webkit-animation: rot 6s linear infinite;
}
.outer div:nth-child(5) {
position: absolute;
z-index: 1;
top: 570px;
left: 250px;
background: url(../images/hairboy.png) center center no-repeat;
background-size: contain;
-webkit-animation: rot 6s linear infinite;
}
.outer div:nth-child(6) {
position: absolute;
z-index: 1;
top: 480px;
left: 50px;
background: url(../images/mimi.png) center center no-repeat;
background-size: contain;
-webkit-animation: rot 6s linear infinite;
}
.outer div:nth-child(7) {
position: absolute;
z-index: 1;
top: 280px;
left: -20px;
background: url(../images/mudog.png) center center no-repeat;
background-size: contain;
-webkit-animation: rot 6s linear infinite;
}
.outer div:nth-child(8) {
position: absolute;
z-index: 1;
top: 120px;
left: 50px;
background: url(../images/mimi.png) center center no-repeat;
background-size: contain;
-webkit-animation: rot 6s linear infinite;
}
@-webkit-keyframes rot {
from {
-webkit-transform: rotateZ(360deg);
-webkit-transform-origin: 50% top;
}
to {
-webkit-transform: rotateZ(0deg);
-webkit-transform-origin: 50% top;
}
}
.inner {
position: absolute;
top: 300px;
left: 200px;
width: 200px;
height: 400px;
background: url(../images/bracketsmall.png) center center no-repeat;
}
</style>
</head>
<body>
<div class="wrap">
<div class="con">
<div class="outer clearfix">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div class="font clearfix">
</div>
<div class="inner"></div>
</div>
</div>
<script></script>
</body>
</html>复制代码
今天写完这篇博文很开心,因为我今天懂得怎么弄掘金的链接,怎么弄代码块了,掘金确实是比网易博客好用多了,哈哈哈哈哈哈~~~