-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
165 lines (135 loc) · 3.89 KB
/
index.html
File metadata and controls
165 lines (135 loc) · 3.89 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Ambassadors 3D</title>
<style>
body {
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #111;
overflow: hidden;
}
.scene {
width: 90vh;
height: auto;
perspective: 1000px;
}
.image-container {
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 0.1s ease;
cursor: grab;
touch-action: none;
}
.image-container:active {
cursor: grabbing;
}
img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
transform: translateZ(0);
backface-visibility: hidden;
}
img {
user-drag: none;
-webkit-user-drag: none;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
</style>
</head>
<body>
<div class="scene">
<div class="image-container" id="imageContainer">
<img src="NG1314.jpg" alt="The Ambassadors by Hans Holbein the Younger" id="image" />
</div>
</div>
<script>
const container = document.getElementById('imageContainer');
const image = document.getElementById('image');
let isDragging = false;
let lastX, lastY;
let rotX = 0, rotY = 0;
let imgRotation = 0;
let scale = 1;
let initialDistance = null;
// Mouse Events
container.addEventListener('mousedown', (e) => {
isDragging = true;
lastX = e.clientX;
lastY = e.clientY;
});
window.addEventListener('mousemove', (e) => {
if (!isDragging) return;
handleRotation(e.clientX, e.clientY);
});
window.addEventListener('mouseup', () => {
isDragging = false;
});
// Touch Events
container.addEventListener('touchstart', (e) => {
if (e.touches.length === 1) {
isDragging = true;
lastX = e.touches[0].clientX;
lastY = e.touches[0].clientY;
} else if (e.touches.length === 2) {
initialDistance = getDistance(e.touches[0], e.touches[1]);
}
});
container.addEventListener('touchmove', (e) => {
if (e.touches.length === 1 && isDragging) {
e.preventDefault();
handleRotation(e.touches[0].clientX, e.touches[0].clientY);
} else if (e.touches.length === 2) {
e.preventDefault();
const currentDistance = getDistance(e.touches[0], e.touches[1]);
if (initialDistance) {
const zoom = currentDistance / initialDistance;
scale = Math.min(Math.max(zoom, 0.5), 3); // Clamp zoom between 0.5x and 3x
image.style.transform = `rotate(${imgRotation}deg) scale(${scale})`;
}
}
}, { passive: false });
container.addEventListener('touchend', (e) => {
if (e.touches.length < 2) {
initialDistance = null;
}
if (e.touches.length === 0) {
isDragging = false;
}
});
function handleRotation(currentX, currentY) {
const deltaX = currentX - lastX;
const deltaY = currentY - lastY;
rotY += deltaX * 0.3;
rotX -= deltaY * 0.3;
imgRotation += deltaX * 0.1;
container.style.transform = `rotateX(${rotX}deg) rotateY(${rotY}deg)`;
image.style.transform = `rotate(${imgRotation}deg) scale(${scale})`;
lastX = currentX;
lastY = currentY;
}
function getDistance(touch1, touch2) {
const dx = touch2.clientX - touch1.clientX;
const dy = touch2.clientY - touch1.clientY;
return Math.sqrt(dx * dx + dy * dy);
}
</script>
<!-- Analytics -->
<script src="https://getinsights.io/js/insights.js"></script>
<script>
insights.init('QdIDnJn3qPSrgcg8');
insights.trackPages();
</script>
</body>
</html>