一.要达到的效果:
悬浮在不同按钮上,正方体展示不同的面。
二.效果图:
初始效果:
悬浮在左侧按钮时,正方体旋转。
三:代码链接:
链接: https://pan.baidu.com/s/1BCfn7VGsc7Tr2UTwnw4pLA 提取码: 3235 复制这段内容后打开百度网盘手机App,操作更方便哦
四:源码
-----------------------------------------------------我是分割线----------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>正方体旋转</title>
<style>
body,
ul {
margin: 0;
}
ul {
padding-left: 0;
list-style: none;
}
input {
display: none;
}
.main {
display: flex;
justify-content: space-evenly;
align-items: center;
width: 500px;
height: 500px;
border: 3px solid black;
margin: 50px auto;
background:url("./pic/xiaoli.jpg") center/cover;
}
.clickarea {
width: 80px;
height: 200px;
/* background-color: red; */
}
.clickarea>li {
width: 80px;
height: 30px;
margin-top: 3px;
}
.clickarea>li:nth-child(1) {
background-color: blue;
}
.clickarea>li:nth-child(2) {
background-color: cadetblue;
}
.clickarea>li:nth-child(3) {
background-color: blueviolet;
}
.clickarea>li:nth-child(4) {
background-color: brown;
}
.clickarea>li:nth-child(5) {
background-color: skyblue;
}
.clickarea>li:nth-child(6) {
background-color: pink;
}
.squre {
width: 200px;
height: 200px;
float: left;
/* border: 3px solid black; */
/* perspective: 1000px; */
transform-style: preserve-3d;
/* animation: animate1 8s linear infinite; */
transition: 0.5s linear;
transform: rotateX(0deg) rotateY(0deg);
}
.squre>div {
position: absolute;
width: 200px;
height: 200px;
font-size: 16px;
line-height: 200px;
color: white;
font-weight: bold;
text-align: center;
}
.up {
background-color: blue;
/* transform-origin: top; */
transform: translateZ(100px);
}
.down {
background-color: blueviolet;
transform: translateZ(-100px);
/* transform-origin: bottom; */
}
.left {
background-color: brown;
/* transform-origin: left; */
transform: translateY(-100px) rotateX(90deg);
}
.right {
background-color: cadetblue;
transform: translateY(100px) rotateX(-90deg);
/* transform-origin: right; */
}
.forward {
background-color: skyblue;
transform: translateX(-100px) rotateY(90deg);
}
.back {
background-color: pink;
transform: translateX(100px) rotateY(90deg);
}
/* @keyframes animate1 {
0% {
transform: rotateX(0deg) rotateY(0deg);
}
100% {
transform: rotateX(360deg) rotateY(360deg);
} */
input:nth-child(1):hover~.main>.squre {
transform: rotateX(0deg) rotateY(0deg);
}
input:nth-child(2):hover~.main>.squre {
transform: rotateX(90deg) rotateY(0deg);
}
input:nth-child(3):hover~.main>.squre {
transform: rotateX(180deg) rotateY(0deg) rotate(180deg);
}
input:nth-child(4):hover~.main>.squre {
transform: rotateX(270deg) rotateY(0deg);
}
input:nth-child(5):hover~.main>.squre {
transform: rotateX(0deg) rotateY(90deg);
}
input:nth-child(6):hover~.main>.squre {
transform: rotateX(0deg) rotateY(-90deg);
}
input:nth-child(1):hover~.main>.clickarea>li:nth-child(1){
border: 2px solid skyblue;
}
input:nth-child(2):hover~.main>.clickarea>li:nth-child(2) {
border: 2px solid skyblue;
}
input:nth-child(3):hover~.main>.clickarea>li:nth-child(3) {
border: 2px solid skyblue;
}
input:nth-child(4):hover~.main>.clickarea>li:nth-child(4) {
border: 2px solid skyblue;
}
input:nth-child(5):hover~.main>.clickarea>li:nth-child(5) {
border: 2px solid skyblue;
}
input:nth-child(6):hover~.main>.clickarea>li:nth-child(6) {
border: 2px solid skyblue;
}
</style>
</head>
<body>
<input type="radio" name="radio" id="radio1">
<input type="radio" name="radio" id="radio2">
<input type="radio" name="radio" id="radio3">
<input type="radio" name="radio" id="radio4">
<input type="radio" name="radio" id="radio5">
<input type="radio" name="radio" id="radio6">
<div class="main">
<ul class="clickarea">
<li>
<label for="radio1">
<img src="./pic/chang_1.jpg" width="80px" height="30px" alt="">
</label>
</li>
<li>
<label for="radio2">
<img src="./pic/chang_2.jpg" width="80px" height="30px" alt="">
</label>
</li>
<li>
<label for="radio3">
<img src="./pic/boren_chang_1.jpg" width="80px" height="30px" alt="">
</label>
</li>
<li>
<label for="radio4">
<img src="./pic/kakaxi_chang_2.jpg" width="80px" height="30px" alt="">
</label>
</li>
<li>
<label for="radio5">
<img src="./pic/mingren_chang_4.jpg" width="80px" height="30px" alt="">
</label>
</li>
<li>
<label for="radio6">
<img src="./pic/kakaxi_chang_3.jpg" width="80px" height="30px" alt="">
</label>
</li>
</ul>
<div class="squre">
<div class="up">
<img src="./pic/mingren2.jpg" width="200px" height="200px" alt="">
</div>
<div class="down">
<img src="./pic/mingren_t_zheng_2.jpg" width="200px" height="200px" alt="">
</div>
<div class="left">
<img src="./pic/woailuo_zheng_1.jpg" width="200px" height="200px" alt="">
</div>
<div class="right">
<img src="./pic/mingren1.jpg" width="200px" height="200px" alt="">
</div>
<div class="forward">
<img src="./pic/mingren_zheng_5.jpg" width="200px" height="200px" alt="">
</div>
<div class="back">
<img src="./pic/mingren_t_zheng_2.jpg" width="200px" height="200px" alt="">
</div>
</div>
</div>
</body>
</html>
-----------------------------------------------------我是分割线----------------------------------------------------------------------------------