js达成可旋转的立方人体模型型,CSS3落到实处立

作者: 韦德国际1946国际网址  发布:2019-07-01

js达成可旋转的立方人体模型型,CSS3落到实处立方体旋转。那是多少个差不离的立方体应用,他是过多立方旋转变换的底蕴,比方落到实处3D轮播图的兑现等。

js达成可旋转的立方人体模型型,js旋转立方人体模型型

那是一个归纳的立方体应用,他是数不清立方旋调换换的根基,举例落到实处3D轮播图的贯彻等。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>可旋转立方体效果</title>
  <style type="text/css">
    *{padding: 0; margin: 0}
    img{border: 0}
    ul li{list-style: none}
    ul{width: 200px; height: 200px; margin: 100px auto;
    position: relative; -webkit-transform-style: preserve-3d ;
      /* perspective: 100px;*/
    }
    /*绕中心旋转,坐标轴会随旋转而旋转*/
    li{width:200px;height:200px;position:absolute;text-align:center;line-height:200px;font-size:80px;font-weight:bold;color:#fff;}
    /*构造六个面*/
    li:nth-child(1){background:rgba(255,0,0,1);-webkit-transform:rotateX(90deg)  translateZ(100px);}
    li:nth-child(2){background:rgba(0,255,255,1);-webkit-transform:rotateX(270deg) translateZ(100px);}
    li:nth-child(3){background:rgba(255,0,255,1);-webkit-transform:rotateY(90deg) translateZ(100px);}
    li:nth-child(4){background:rgba(0,255,0,1);-webkit-transform:rotateY(270deg) translateZ(100px);}
    li:nth-child(5){background:rgba(200,200,0,1);-webkit-transform:translateZ(-100px);}
    li:nth-child(6){background:rgba(0,0,255,1);-webkit-transform: translateZ(100px) ;}
    .button{
      width: 200px; margin: 20px auto;
      position: relative;
      cursor: pointer;
    }
    input{
      width: 50px; height: 30px;
      position: absolute;
      cursor: pointer;
    }
    /*按钮的绝对定位*/
    input:nth-child(1){left: 100px; top: 0}
    input:nth-child(2){left:200px;top:50px;}
    input:nth-child(3){left:0px;top:50px;}
    input:nth-child(4){left:100px;top:100px;}
    input:nth-child(5){left:100px;top:50px;}
  </style>
  <script type="text/javascript">
    window.onload = function () {
      var x = 0, y = 0;
      var ul = document.getElementById('ul');
      var inputs = document.getElementsByTagName('input');
      for (var i = 0; i<inputs.length; i  ){
        inputs[i].onclick = run;
      }
      function run() {
        /*渐变*/
        ul.style.webkitTransition = '-webkit-transform 3s linear';
        ul.style.oTransition = '-o-transform 3s linear';
        ul.style.transition = 'transform 3s linear';
        /*旋转的规则,就是x,y方向的deg改变*/
        if(inputs[0]==this){x =90;}
        if(inputs[1]==this){y =90;}
        if(inputs[2]==this){y-=90;}
        if(inputs[3]==this){x-=90;}
        if (inputs[4] == this){
          x = 0; y = 0;
          ul.style.webkitTransition = '-webkit-transform .1s linear';
          ul.style.oTransition = '-o-transform .1s linear';
          ul.style.transition = 'transform .1s linear';
        }
        ul.style.webkitTransform = 'rotateX('   x   'deg) rotateY('   y   'deg)';
        ul.style.oTransform = 'rotateX('   x   'deg) rotateY('   y   'deg)';
        ul.style.transform = 'rotateX('   x   'deg) rotateY('   y   'deg)';
      }
      document.addEventListener('keydown', function(e){
        ul.style.webkitTransition='-webkit-transform 3s linear';
        switch(e.keyCode){
          case 37:  y -= 90;  //左箭头
            break;
          case 38:  x  = 90;  //上箭头
            break;
          case 39:  y  = 90;  //下箭头
            break;
          case 40:  x -= 90;  //右箭头
            break;
          case 13:  x=0; y=0;  //回车 (当回车时,迅速转回初始状态)
            ul.style.webkitTransition='-webkit-transform 0.1s linear';
            break;
        }
        ul.style.webkitTransform = "rotateX(" x "deg) rotateY(" y "deg)"; //变换效果(沿X轴和Y轴旋转)
      }, false);document.addEventListener("keydown", function (e) {
        ul.style.webkitTransition = '-webkit-transform 3s linear';
        ul.style.oTransition = '-o-transform 3s linear';
        ul.style.transition = 'transform 3s linear';
        switch(e.keyCode){
          case 37:
        }
      })
      /* function run(){
        ul.style.webkitTransition='-webkit-transform 3s linear'; //设置立方体变换的属性、持续时间、动画类型
        if(inputs[0]==this){x =90;}
        if(inputs[1]==this){y =90;}
        if(inputs[2]==this){y-=90;}
        if(inputs[3]==this){x-=90;}
        if(inputs[4]==this){x=0;y=0; ul.style.webkitTransition='-webkit-transform 0.1s linear';}  //当点击重置按钮时,迅速转回到初始状态。
        ul.style.webkitTransform = "rotateX(" x "deg) rotateY(" y "deg)";  //变换效果(沿X轴和Y轴旋转)
      }*/
    }
  </script>
</head>
<body>
<ul id="ul">
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
  <li>6</li>
</ul>
<div class="container">
</div>
<div class="button">
  <input type="button" value="上">
  <input type="button" value="右">
  <input type="button" value="左">
  <input type="button" value="下">
  <input type="button" value="重置">
</div>

</body>
</html>

那是一个简短的立方体应用,他是成都百货上千立方旋调换换的底蕴,比方落实3D轮播图的落到实处等。...

CSS3贯彻立方体旋转

图片 1

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>可旋转立方体效果</title>
  <style type="text/css">
    *{padding: 0; margin: 0}
    img{border: 0}
    ul li{list-style: none}
    ul{width: 200px; height: 200px; margin: 100px auto;
    position: relative; -webkit-transform-style: preserve-3d ;
      /* perspective: 100px;*/
    }
    /*绕中心旋转,坐标轴会随旋转而旋转*/
    li{width:200px;height:200px;position:absolute;text-align:center;line-height:200px;font-size:80px;font-weight:bold;color:#fff;}
    /*构造六个面*/
    li:nth-child(1){background:rgba(255,0,0,1);-webkit-transform:rotateX(90deg)  translateZ(100px);}
    li:nth-child(2){background:rgba(0,255,255,1);-webkit-transform:rotateX(270deg) translateZ(100px);}
    li:nth-child(3){background:rgba(255,0,255,1);-webkit-transform:rotateY(90deg) translateZ(100px);}
    li:nth-child(4){background:rgba(0,255,0,1);-webkit-transform:rotateY(270deg) translateZ(100px);}
    li:nth-child(5){background:rgba(200,200,0,1);-webkit-transform:translateZ(-100px);}
    li:nth-child(6){background:rgba(0,0,255,1);-webkit-transform: translateZ(100px) ;}
    .button{
      width: 200px; margin: 20px auto;
      position: relative;
      cursor: pointer;
    }
    input{
      width: 50px; height: 30px;
      position: absolute;
      cursor: pointer;
    }
    /*按钮的绝对定位*/
    input:nth-child(1){left: 100px; top: 0}
    input:nth-child(2){left:200px;top:50px;}
    input:nth-child(3){left:0px;top:50px;}
    input:nth-child(4){left:100px;top:100px;}
    input:nth-child(5){left:100px;top:50px;}
  </style>
  <script type="text/javascript">
    window.onload = function () {
      var x = 0, y = 0;
      var ul = document.getElementById('ul');
      var inputs = document.getElementsByTagName('input');
      for (var i = 0; i<inputs.length; i  ){
        inputs[i].onclick = run;
      }
      function run() {
        /*渐变*/
        ul.style.webkitTransition = '-webkit-transform 3s linear';
        ul.style.oTransition = '-o-transform 3s linear';
        ul.style.transition = 'transform 3s linear';
        /*旋转的规则,就是x,y方向的deg改变*/
        if(inputs[0]==this){x =90;}
        if(inputs[1]==this){y =90;}
        if(inputs[2]==this){y-=90;}
        if(inputs[3]==this){x-=90;}
        if (inputs[4] == this){
          x = 0; y = 0;
          ul.style.webkitTransition = '-webkit-transform .1s linear';
          ul.style.oTransition = '-o-transform .1s linear';
          ul.style.transition = 'transform .1s linear';
        }
        ul.style.webkitTransform = 'rotateX('   x   'deg) rotateY('   y   'deg)';
        ul.style.oTransform = 'rotateX('   x   'deg) rotateY('   y   'deg)';
        ul.style.transform = 'rotateX('   x   'deg) rotateY('   y   'deg)';
      }
      document.addEventListener('keydown', function(e){
        ul.style.webkitTransition='-webkit-transform 3s linear';
        switch(e.keyCode){
          case 37:  y -= 90;  //左箭头
            break;
          case 38:  x  = 90;  //上箭头
            break;
          case 39:  y  = 90;  //下箭头
            break;
          case 40:  x -= 90;  //右箭头
            break;
          case 13:  x=0; y=0;  //回车 (当回车时,迅速转回初始状态)
            ul.style.webkitTransition='-webkit-transform 0.1s linear';
            break;
        }
        ul.style.webkitTransform = "rotateX(" x "deg) rotateY(" y "deg)"; //变换效果(沿X轴和Y轴旋转)
      }, false);document.addEventListener("keydown", function (e) {
        ul.style.webkitTransition = '-webkit-transform 3s linear';
        ul.style.oTransition = '-o-transform 3s linear';
        ul.style.transition = 'transform 3s linear';
        switch(e.keyCode){
          case 37:
        }
      })
      /* function run(){
        ul.style.webkitTransition='-webkit-transform 3s linear'; //设置立方体变换的属性、持续时间、动画类型
        if(inputs[0]==this){x =90;}
        if(inputs[1]==this){y =90;}
        if(inputs[2]==this){y-=90;}
        if(inputs[3]==this){x-=90;}
        if(inputs[4]==this){x=0;y=0; ul.style.webkitTransition='-webkit-transform 0.1s linear';}  //当点击重置按钮时,迅速转回到初始状态。
        ul.style.webkitTransform = "rotateX(" x "deg) rotateY(" y "deg)";  //变换效果(沿X轴和Y轴旋转)
      }*/
    }
  </script>
</head>
<body>
<ul id="ul">
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
  <li>6</li>
</ul>
<div class="container">
</div>
<div class="button">
  <input type="button" value="上">
  <input type="button" value="右">
  <input type="button" value="左">
  <input type="button" value="下">
  <input type="button" value="重置">
</div>

</body>
</html>
 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>立方体旋转</title>
 6     <style>
 7         .box{
 8             width: 250px;
 9             height: 250px;
10             border: 1px dashed red;
11             margin:100px auto;
12             position: relative;
13             transform-style: preserve-3d;
14             border-radius: 50%;
15             /*transform: rotateX(30deg) rotateY(-30deg);*/
16 
17             animation: gun 8s linear infinite;
18         }
19         .box>div{
20             width: 100%;
21             height: 100%;
22             position: absolute;
23             text-align: center;
24             line-height: 250px;
25             font-size: 60px;
26             color: green;
27         }
28         .left{
29             background-color: rgba(255,0,0,0.3);
30             /*变换中心*/
31             transform-origin: left;
32             /*变换*/
33             transform:rotateY(90deg) translateX(-125px);
34         }
35         .right{
36             background-color: rgba(0,0,255,0.3);
37             transform-origin: right;
38             transform: rotateY(90deg) translateX(125px);
39         }
40         .forward{
41             background-color: rgba(0,255,255,0.3);
42             transform: translateZ(125px);
43         }
44         .back{
45             background-color: rgba(255,255,0,0.3);
46             transform: translateZ(-125px);
47         }
48         .up{
49             background-color: rgba(99,66,33,0.3);
50             transform: rotateX(90deg) translateZ(125px);
51         }
52         .down{
53             background-color: rgba(255,0,255,0.3);
54             transform: rotateX(-90deg) translateZ(125px);
55         }
56         @keyframes gun {
57             0%{
58                 transform: rotateX(0deg) rotateY(0deg);
59             }
60             100%{
61                 transform: rotateX(360deg) rotateY(360deg);
62             }
63         }
64     </style>
65 </head>
66 <body>
67     <div class="box">
68         <div class="up">上</div>
69         <div class="down">下</div>
70         <div class="left">左</div>
71         <div class="right">右</div>
72         <div class="forward">前</div>
73         <div class="back">后</div>
74     </div>
75 </body>
76 </html>

运行效果:

旋转的立方体

本文由韦德国际1946发布于韦德国际1946国际网址,转载请注明出处:js达成可旋转的立方人体模型型,CSS3落到实处立

关键词: css3 韦德国际 可视化的视野 ThreeJs