css3立方體制作
阿新 • • 發佈:2019-01-29
之前看過一些複雜翻轉輪播的實現,結果發現實現思路與自己的想法大相徑庭。其中每一個翻轉體(立方體)的實現還是很簡潔易懂的,在此記錄下來。程式碼直接奉上,親測可用哦。
<html>
<head>
<meta charset="utf-8">
<title>cube3D立方體</title>
</head>
<body>
<div id="cube">
<div>1</div>
<div>2</ div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
</body>
</html>
body{
margin:0px;
padding:0px;
perspective: 1000px; /*設定景深*/
transform-style: preserve-3d;
}
#cube{
position:relative;
top :40%;
left:0;
width: 200px;
height:200px;
border:1px solid #333;
margin:0px auto;
transform-style: preserve-3d;
transform-origin: 50% 50% -101px;
transform: rotateY(0deg);
transition-timing-function:
}
#cube:hover{
transform: rotateY(360deg);
transition: 5s;
}
#cube div{
position :absolute;
width: 200px;
height:200px;
border:1px solid red;
}
#cube div:nth-child(1){
position:absolute;
top:0px;
}
#cube div:nth-child(2){
position:absolute;
top:-202px;
transform-origin:50% 100%;
transform:rotateX(90deg);
}
#cube div:nth-child(3){
position:absolute;
top:202px;
transform-origin:50% 0;
transform:rotateX(-90deg);
}
#cube div:nth-child(4){
position:absolute;
left:-202px;
transform-origin:100% 50%;
transform:rotateY(-90deg);
}
#cube div:nth-child(5){
position:absolute;
left:202px;
transform-origin:0 50%;
transform:rotateY(90deg);
}
#cube div:nth-child(6){
position:absolute;
top:0px;
transform: translateZ(-202px);
}