<!doctype html>
<html>
<head>
<meta charset="UTF-8">
</head>
<style>
-webkit-perspective:800;
-webkit-perspective-origin: 50% 50%;
-webkit-transform-style:-webkit-preserve-3d;
}
#fk{
width:300px;
height:300px;
background:#69e;
position:relative;
top:50px;
left:500px;
-webkit-transform:rotateX(0deg);
-webkit-transform:rotateY(0deg);
-webkit-transform:rotateZ(0deg);
}
#xz{
width:300px;
}
#yz{
width:300px;
}
#zz{
width:300px;
}
</style>
<body>
<div id="pm"><div id="fk"></div></divs>
<input id="xz" type="range" value="0">这是X轴运动<br><br>
<input id="yz" type="range" value="0">这是Y轴运动<br><br>
<input id="zz" type="range" value="0">这是Z轴运动
<script>
var fk = document.getElementById('fk');//获取fk
var xz = document.getElementById('xz');//获取x轴按钮
var yz = document.getElementById('yz');//获取y轴按钮
var zz = document.getElementById('zz');//获取z轴按钮
var jd=10;//声明一个角度变量
var isDown = false;//声明一个空变量用于控制函数
xz.onmousedown = function(){//设置x轴按下事件
isDown = true;
}
xz.onmousemove = function(){//设置x轴按下并且移动事件
if(isDown==true){//当鼠标按下之后才会运行
jd+=10;//每+10度
fk.style.transform = 'rotateX('+jd+'deg)';//把角度重新赋值给fk
}
}
xz.onmouseup = function(){//当鼠标抬起的时候让isdown返回false.这样移动事件就不会触发了
isDown = false;
}
yz.onmousedown = function(){
isDown = true;
}
yz.onmousemove = function(){
if(isDown==true){
jd+=10;
fk.style.transform = 'rotateY('+jd+'deg)';
}
}
yz.onmouseup = function(){
isDown = false;
}
zz.onmousedown = function(){
isDown = true;
}
zz.onmousemove = function(){
if(isDown==true){
jd+=10;
fk.style.transform = 'rotateZ('+jd+'deg)';
}
}
zz.onmouseup = function(){
isDown = false;
}
</script>
</body>
</html>