forked from yueyingjun/3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation.html
204 lines (172 loc) · 5.91 KB
/
animation.html
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
html,body{
width:100%;height:100%;overflow: hidden;
padding:0;margin:0;
}
.scene{
width:100%;height:100%;
perspective: 500px;
}
.box{
width:100%;height:100%;
position: relative;
transform-style: preserve-3d;
transform-origin: center center 600px;
transform: rotateY(-180deg);
}
.box .panel{
width:100%;height:100%;
position: absolute;
}
.box .panel:nth-child(1){
background: #ccc;
transform-origin: top;
transform: rotateX(90deg);
background: url(img/tianhuaban2.jpg);
background-size: 100px 100px;
box-shadow: 0 0 250px #aaa inset;
}
.box .panel:nth-child(2){
background: #ccc;
transform-origin: left;
transform: rotateY(-90deg);
box-shadow: 0 0 250px #aaa inset;
}
.box .panel:nth-child(3){
box-shadow: 0 0 250px #aaa inset;
background: #ccc url(img/chuanghu2.jpg) no-repeat center;
}
.box .panel:nth-child(4){
background: #ccc;
transform-origin: right;
transform: rotateY(90deg);
box-shadow: 0 0 250px #aaa inset;
}
.box .panel:nth-child(5){
background: blue;
transform-origin: bottom;
background: url(img/diban.jpg) repeat;
}
.box .panel:nth-child(6){
background: url(img/1.jpg) no-repeat;
background-size: cover;
}
.phone1{
width:100%;height:30%;
background:green;position: absolute;
left:10px;top:0;bottom: 0;
margin: auto;
}
.phone2{
width:100%;height:30%;
background:green;position: absolute;
right:10px;top:0;bottom: 0;
margin: auto;
}
.phone3{
width:100%;height:30%;
background:green;position: absolute;
left:0;right:0px;top:0;bottom: 0;
margin: auto;
}
</style>
<script>
window.onload=function(){
var clientW=document.documentElement.clientWidth;
var clientH=document.documentElement.clientHeight;
var box=document.querySelector(".box");
box.style.transformOrigin="center center "+clientW/2+"px"
var lastPanel=document.querySelector(".panel:last-child");
var panel1=document.querySelector(".panel:nth-child(1)");
panel1.style.width=clientW+"px";
panel1.style.height=clientW+"px";
var panel5=document.querySelector(".panel:nth-child(5)");
panel5.style.width=clientW+"px";
panel5.style.height=clientW+"px"
panel5.style.top=-(clientW-clientH)+"px";
panel5.style.transform="rotateX(-90deg)";
lastPanel.style.transform="translateZ("+clientW+"px) rotateY(180deg)";
var angle=0;
document.ondblclick=function(){
angle=0;
box.style.transition="transform 2s ease";
box.style.transform="translateZ(-500px) rotate3d(0,1,0,0deg)"
}
document.onmousedown=function(e){
var startx= e.clientX;
var starty= e.clientY;
var angle1=0;
document.onmousemove=function(e){
box.style.transition="none";
var movex= e.clientX;
var movey= e.clientY;
angle1=Math.abs(movex-startx)>Math.abs(movey-starty)?movex-startx:movey-starty;
var endx=movex-clientW/2;
var endy=movey-clientH/2;
var mo=Math.sqrt(endx*endx+endy*endy);
var x=endx/mo;
var y=endy/mo;
console.log(angle+angle1)
box.style.transform="translateZ(-500px) rotate3d("+0+","+1+",0, "+(angle+angle1)+"deg)";
e.preventDefault();
}
document.onmouseup=function(){
document.onmousemove=null;
document.onmouseup=null;
angle+=angle1;
angle%=360;
}
e.preventDefault();
}
var phones=document.querySelectorAll(".phone");
for(var i=0;i<phones.length;i++){
phones[i].onclick=function(e){
var cx= e.clientX;
var cy= e.clientY;
var a=Math.atan2(cx-clientW/2,190-100)*180/Math.PI;
box.style.transformOrigin="center center "+(clientW/2-100)+"px"
box.style.transform="translate3d("+0+"px,0,100px) rotateY("+a+"deg)"
/*if(a>-74&&a<74){
box.style.transform="translate3d("+(clientW/2-cx)+"px,0,300px) rotateY(0)"
}else if(a<-74&&a>-90){
//左
alert(1);
box.style.transform="translate3d("+(clientW/2-cx)+"px,0,300px) rotateY(-90deg)"
}else if(a>74&&a<90){
//右
box.style.transform="translate3d("+(clientW/2-cx)+"px,0,300px) rotateY(90deg)"
}
*/
}
}
}
</script>
</head>
<body>
<div class="scene">
<div class="box">
<div class="panel">
</div>
<div class="panel">
<div class="phone1 phone">
</div>
</div>
<div class="panel">
<div class="phone3 phone">
</div>
</div>
<div class="panel">
<div class="phone2 phone">
</div>
</div>
<div class="panel"></div>
<div class="panel"></div>
</div>
</div>
</body>
</html>