今天带了css3新属性3d
<!DOCTYPE html>
<html>
<head>
<meta charset=
"UTF-8"
>
<title></title>
<style type=
"text/css"
>
#a{
width: 200px;
height: 200px;
margin: 200px auto;
position:relative;
transform-style: preserve-3d;
transform: perspective(1000px) rotateY(30deg) rotateX(30deg);
}
#a>div{
position:absolute;
width: 200px;
height: 200px;
border: 1px solid #000000;
text-align: center;
line-height: 200px;
}
#a>div:nth-child(1){
transform: translateZ(100px);
background: rgba(0,0,255,0.2);
}
#a>div:nth-child(2){
transform: translateZ(-100px);
background: rgba(0,255,0,0.2);
}
#a>div:nth-child(3){
transform: rotateX(90deg) translateZ(100px);
background: rgba(255,0,0,0.2);
}
#a>div:nth-child(4){
transform: rotateX(90deg) translateZ(-100px);
background: rgba(255,255,0,0.2);
}
#a>div:nth-child(5){
transform: rotateY(90deg) translateZ(-100px);
background: rgba(0,255,255,0.2);
}
/
#a>div:nth-child(6){
transform: rotateY(90deg) translateZ(100px);
background: rgba();
}
</style>
</head>
<body>
<div id=
"a"
>
<div>前</div>
<div>后</div>
<div>上</div>
<div>下</div>
<div>左</div>
<div>右</div>
</div>
</body>
<script type=
"text/javascript"
>
var
a=document.getElementById(
"a"
)
var
x;
var
y;
a.onmousedown=
function
(ev){
x=ev.clientX
y=ev.clientY
document.onmousemove=
function
(ev){
var
x1=ev.clientX-x+30
var
y1=ev.clientY-y-30
a.style.transform=
"perspective(1000px) rotateY("
+ x1 +
"deg) rotateX("
+ -(y1) +
"deg)"
;
}
document.onmouseup=
function
(){
document.onmousemove=null;
}
}
</script>
</html>