正方体旋转css简单实现第二种
------父视图必须添加透明度perspective:5000px随便大小。越大视觉离得越远,物体更接近原来大小不会变形-----
---------必须在父视图添加transfrom-style:preserve-3d 保证子元素已3d样式出现且不会改变子元素自身的坐标轴-------
-------效果是旋转的父视图div,所以给div添加的transtion过度动画--------
这个效果是以xyz轴分别先旋转再位移,没有更改基准点,区别于上一个方案
IMG_2503.GIF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0px;
padding: 0px;
}
.max {
margin: 250px auto;
}
.max,.box {
position: relative;
width: 200px;
height: 200px;
perspective: 5000px;
}
.box {
transform-style: preserve-3d;
transition: all 4.5s ease;
}
.box p {
position: absolute;
left: 0px;
top: 0px;
width: 200px;
height: 200px;
font: bold 50px/200px "微软雅黑";
text-align: center;
}
.box p:nth-child(1){
background-color: rgba(233, 1, 111, 0.2);
transform:rotateX(360deg) translateZ(-100px);
}
.box p:nth-child(6){
background-color: rgba(34, 21, 221, 0.2);
transform:translateZ(100px);
}
.box p:nth-child(2){
background-color: rgba(233, 1, 111, 0.2);
transform:rotateY(90deg) translateZ(100px);
}
.box p:nth-child(5){
background-color: rgba(241, 187, 10, 0.2);
transform:rotateY(-90deg) translateZ(100px);
}
.box p:nth-child(3){
background-color: rgba(133, 223, 16, 0.2);
transform:rotateX(-270deg) translateZ(100px);
}
.box p:nth-child(4){
background-color: rgba(26, 151, 135, 0.2);
transform:rotateX(-90deg) translateZ(100px);
}
.box:hover{
transform: rotateX(360deg) rotateY(360deg);
}
</style>
</head>
<body>
<div class="max">
<div class="box">
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
<p>6</p>
</div>
</div>
</body>
</html>
网友评论