2018-10-07

"Hello World, Hello Blog"

Posted by wudimingwo on December 15, 2018
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewprot" content="width=device-width, initial-scale=1.0"/>
        <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
        <title>dddd</title>
        <style type="text/css">
          *{
            margin: 0;
            padding: 0;
          }
          .box{
            position: relative;
            
            width: 100vw;
            height: 100vh;
            border: 1px solid black;
            box-sizing: border-box;
            
            perspective: 500px;
            transform-style: preserve-3d;
            transform-origin: center center;
          }
          
            .item{
              margin: 100px auto;
               width: 300px;
               height: 450px;
               background-image: url(img/2test.jpg);
               background-size: 100% 100%;
               /*transform: rotate3d(1,2,3,45deg);*/
            }
            button{
              position: absolute;
              right: 10px;
              top: 40%;
              width: 200px;
              height: 50px;
            }
        </style>
    </head>
    <body>
      
          <div class="box">
            <div class="item"></div>
            <button>z轴:左右键滑翔</button>
          </div>
        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <script type="text/javascript">
//          随着鼠标旋转
//          左右,移动y轴转,
//          上下移动 x轴转,
            var data3d = {
              disx : 0,
              disy : 0,
              disz : 0
            }
            
            
            
            $(".box").on('mousedown',function (e) {
            	var firstX = e.clientX;
            	var firstY = e.clientY;
            	
            	$(document).on('mousemove',function (e) {
            		//获取差值,刷新初值
            		console.log(123);
            		var disX = e.clientX - firstX;
            		var disY = e.clientY - firstY;
            		data3d.disx += disX;
            		data3d.disy += disY;
            		rotateStart(data3d);
            		firstX = e.clientX;
            		firstY = e.clientY;
            	});
            	$(document).on('mouseup',function () {
            		$(document).off();
            	});
            });
            
            $(document).add('.box').add('button').on('contextmenu',function (e) {
            	e.preventDefault();
            })
            
            $("button").on('mousedown',function (e) {
            	e.stopPropagation();
            	var firstX = e.clientX;
            	$(this).on('mousemove',function (e) {
            	  e.stopPropagation();
            	  var disX = e.clientX - firstX;
            		data3d.disz += disX;
            	  rotateStart(data3d);
            		firstX = e.clientX;
            	});
            	$(this).on('mouseup',function (e) {
            		$(this).off('mousemove mouseup');
            	})
            })
            

            
            function rotateStart (data3d) {
            	//获取现有值
            	$(".item").css({'transform':'rotateY(' + data3d.disx*0.1 + 'deg) ' + 'rotateX(' + data3d.disy*0.1 + 'deg) ' + 'rotateZ('+ data3d.disz*0.1 +'deg)' });
            	
            }
            
            
            
        </script>
    </body>
</html>