-
Notifications
You must be signed in to change notification settings - Fork 0
/
plinth.html
169 lines (140 loc) · 3.73 KB
/
plinth.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>White Cube Website</title>
<style>
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
.wall {
width: 100%;
height: 100%;
z-index: -2;
position: fixed;
}
.floor {
background-color: #ccc;
height: 25vh;
width: 100%;
position: fixed;
bottom: 0;
z-index: -1;
}
.wrap {
perspective: 1000px;
perspective-origin: bottom center 100px;
margin-left: auto;
margin-right: auto;
margin-top: 50vh;
display: flex;
justify-content: center;
align-items: center;
z-index: 1;
}
.cube {
position: relative;
width: 200px;
transform-style: preserve-3d;
transform-origin: bottom bottom 100px;
}
.cube div {
position: absolute;
}
.right {
transform: translateZ(-200px) rotateY(270deg) translateX(100px);
transform-origin: bottom right;
background-color: #eee;
width: 150px;
height: 65vh;
}
.left {
transform: translateZ(-200px) rotateY(-270deg) translateX(-100px);
transform-origin: bottom left;
background-color: #eee;
width: 150px;
height: 65vh;
}
.top {
transform: translateZ(-200px) rotateX(-90deg) translateY(-100px);
transform-origin: center top;
background-color: #eee;
height: 150px;
width: 150px;
}
.front {
transform: translateZ(-100px);
background-color: #fff;
width: 150px;
height: 65vh;
}
.bottom {
transform: rotateX(90deg) translateX(-2000px) translateZ(calc(1000px - 65vh));
background-color: #ccc;
width: 4000px;
height: 2000px;
}
</style>
</head>
<body>
<div class="wall"></div>
<!-- <div class="floor"></div> -->
<div class="wrap">
<div class="cube">
<div class="front"> </div>
<div class="top"></div>
<div class="left"></div>
<div class="right"></div>
<div class="bottom"></div>
</div>
</div>
</body>
</html>
<script>
//Global variables
var w = window.innerWidth;
var h = window.innerHeight;
cube = document.getElementsByClassName("cube")[0];
window.onresize = function(event) {
w = window.innerWidth;
h = window.innerHeight;
};
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini/i.test(navigator.userAgent)) {
window.addEventListener('deviceorientation', handleOrientation);
} else {
(function() {
document.onmousemove = handleMouseMove;
function handleMouseMove(e) {
var mouseX = e.pageX;
var mouseY = e.pageY;
var CoorX = mouseX - w / 2;
var CoorY = mouseY - h / 2;
var degX = mapNum(CoorX, -w / 2, w / 2, 25, -25);
var degY = mapNum(CoorY, -h / 2, h / 2, 0, -15);
cube.style.transform = "rotateY(" + degX + "deg)" + "rotateX(" + degY + "deg)";
}
})();
}
function handleOrientation(event) {
var x = event.beta; // In degree in the range [-180,180]
var y = event.gamma; // In degree in the range [-90,90]
// Because we don't want to have the device upside down
// We constrain the x value to the range [-90,90]
if (x > 90) {
x = 90
};
if (x < -90) {
x = -90
};
degX = mapNum(x, -90, 90, 45, -45);
degY = mapNum(y, -90, 90, -45, 45);
cube.style.transform = "rotateY(" + degY + "deg)" + "rotateX(" + degX + "deg)";
}
function mapNum(n, start1, stop1, start2, stop2) {
return ((n - start1) / (stop1 - start1)) * (stop2 - start2) + start2;
};
</script>