第一版本
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>立方体动画</title>
<style type="text/css">
body{
/*设置透视点*/
perspective: 1000px;
}
.lifang{
width: 200px;
height: 200px;
margin: 200px auto;
position: relative;
/*保留子元素的3D效果*/
transform-style: preserve-3d;
/*旋转轴*/
transform: rotate3d(1,1,1,0deg);
transition: all 5s;
}
.lifang:hover{
/*旋转轴*/
transform: rotate3d(1,1,1,720deg);
}
.page{
width: 200px;
height: 200px;
position: absolute;
left: 0;
top: 0;
/*设置透明度*/
opacity: 0.8;
}
.front{
background-image: url(images/GD.jpg);
background-size: 100% auto;
transform: translateZ(100px);
}
.back{
background-image: url(images/GD1.jpg);
background-size: 100% auto;
transform: translateZ(-100px);
}
.right{
background-image: url(images/GD2.jpg);
background-size: auto 100%;
transform: rotateY(90deg) translateZ(100px);
}
.left{
background-image: url(images/GD3.jpg);
background-size: auto 100%;
transform: rotateY(-90deg) translateZ(100px);
}
.top{
background-image: url(images/top.jpg);
background-size: auto 100%;
transform: rotateX(90deg) translateZ(100px);
}
.bottom{
background-image: url(images/GD5.jpg);
background-size: auto 100%;
transform: rotateX(-90deg) translateZ(100px);
}
</style>
</head>
<body>
<div class="lifang">
<div class="page front"></div>
<div class="page back"></div>
<div class="page left"></div>
<div class="page right"></div>
<div class="page top"></div>
<div class="page bottom"></div>
</div>
</body>
</html>
第二版本
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>选项与魔方</title>
<style type="text/css">
body{
/*设置透视点*/
perspective: 1000px;
}
.lifang{
width: 200px;
height: 200px;
margin: 200px auto;
position: relative;
/*保留子元素的3D效果*/
transform-style: preserve-3d;
/*旋转轴*/
transform: rotate3d(1,1,1,0deg);
transition: all 5s;
}
.lifang:hover{
/*旋转轴*/
transform: rotate3d(1,1,1,720deg);
}
.page{
width: 200px;
height: 200px;
position: absolute;
left: 0;
top: 0;
/*设置透明度*/
opacity: 0.8;
}
.front{
background-image: url(images/GD.jpg);
background-size: 100% auto;
transform: translateZ(100px);
}
.back{
background-image: url(images/GD1.jpg);
background-size: 100% auto;
transform: translateZ(-100px);
}
.right{
background-image: url(images/GD2.jpg);
background-size: auto 100%;
transform: rotateY(90deg) translateZ(100px);
}
.left{
background-image: url(images/GD3.jpg);
background-size: auto 100%;
transform: rotateY(-90deg) translateZ(100px);
}
.top{
background-image: url(images/top.jpg);
background-size: auto 100%;
transform: rotateX(90deg) translateZ(100px);
}
.bottom{
background-image: url(images/GD5.jpg);
background-size: auto 100%;
transform: rotateX(-90deg) translateZ(100px);
}
.choose{
width: 900px;
height: 300px;
text-align: center;
margin: 0 auto;
}
.btn{
display: inline-block;
width: 100px;
height: 40px;
font-size: 20px;
color: #999;
border: 1px solid #ccc;
border-radius: 10px;
text-align: center;
line-height: 40px;
}
/*
单选框被选中后,立方体的转动
*/
#front:checked~.lifang{
transform: rotate3d(0,0,0,0deg);
}
#back:checked~.lifang{
transform: rotate3d(0,1,0,180deg);
}
#left:checked~.lifang{
transform: rotate3d(0,1,0,90deg);
}
#right:checked~.lifang{
transform: rotate3d(0,1,0,-90deg);
}
#top:checked~.lifang{
transform: rotate3d(1,0,0,-90deg);
}
#bottom:checked~.lifang{
transform: rotate3d(1,0,0,90deg);
}
/*transform:scale(放大的倍数)*/
#big:checked~.lifang{
transform: scale(2);
}
#small:checked~.lifang{
transform: scale(0.5);
}
/*单选框被选中后,对应的标签按钮的样式*/
#front:checked~.choose [for="front"]{
background: #ccc;
color: #fff;
box-shadow: 0 0 30px #999999
}
#back:checked~.choose [for="back"]{
background: #ccc;
color: #fff;
box-shadow: 0 0 30px #999999
}
#left:checked~.choose [for="left"]{
background: #ccc;
color: #fff;
box-shadow: 0 0 30px #999999
}
#right:checked~.choose [for="right"]{
background: #ccc;
color: #fff;
box-shadow: 0 0 30px #999999
}
#top:checked~.choose [for="top"]{
background: #ccc;
color: #fff;
box-shadow: 0 0 30px #999999
}
#bottom:checked~.choose [for="bottom"]{
background: #ccc;
color: #fff;
box-shadow: 0 0 30px #999999
}
#big:checked~.choose [for="big"]{
background: #ccc;
color: #fff;
box-shadow: 0 0 30px #999999
}
#small:checked~.choose [for="small"]{
background: #ccc;
color: #fff;
box-shadow: 0 0 30px #999999
}
</style>
</head>
<body>
<input type="radio" name="b1" id="front" value="前面" hidden="hidden">
<input type="radio" name="b1" id="back" value="后面" hidden="hidden">
<input type="radio" name="b1" id="left" value="左面" hidden="hidden">
<input type="radio" name="b1" id="right" value="右面" hidden="hidden">
<input type="radio" name="b1" id="top" value="上面" hidden="hidden">
<input type="radio" name="b1" id="bottom" value="下面" hidden="hidden">
<input type="radio" name="b1" id="big" value="放大" hidden="hidden">
<input type="radio" name="b1" id="small" value="缩小" hidden="hidden">
<!-- 魔方 -->
<div class="lifang">
<div class="page front"></div>
<div class="page back"></div>
<div class="page left"></div>
<div class="page right"></div>
<div class="page top"></div>
<div class="page bottom"></div>
</div>
<div class="choose">
<label for="front" class="btn">前面</label>
<label for="back" class="btn">后面</label>
<label for="left" class="btn">左面</label>
<label for="right" class="btn">右面</label>
<label for="top" class="btn">上面</label>
<label for="bottom" class="btn">下面</label>
<label for="big" class="btn">放大</label>
<label for="small" class="btn">缩小</label>
</div>
</body>
</html>