Translsis commited on
Commit
2f2b6a5
·
verified ·
1 Parent(s): a046038

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +117 -38
index.html CHANGED
@@ -57,6 +57,25 @@
57
  .container:active {
58
  cursor: grabbing;
59
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  /* Video nền cho container */
62
  .video-background {
@@ -162,6 +181,9 @@
162
  </div>
163
 
164
  <div id="spider" class="spider">💗</div>
 
 
 
165
  <audio id="bg-music" src="music.mp3" preload="auto"></audio>
166
 
167
  <script>
@@ -172,34 +194,78 @@
172
  let mouseY = window.innerHeight / 2;
173
  let spiderX = mouseX, spiderY = mouseY;
174
 
175
- // Vật cho container
176
- let containerX = window.innerWidth / 2;
177
- let containerY = window.innerHeight / 2;
178
- let containerVelX = 0;
179
- let containerVelY = 0;
180
- let isDragging = false;
181
- let dragOffsetX = 0;
182
- let dragOffsetY = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  const friction = 0.95;
184
  const elasticity = 0.7;
185
  const wallMargin = 50;
186
 
187
- // Khởi tạo vị trí ban đầu
188
- container.style.left = containerX + 'px';
189
- container.style.top = containerY + 'px';
190
- container.style.transform = 'translate(-50%, -50%)';
191
-
192
- // Xử lý kéo thả container
193
- container.addEventListener('mousedown', startDrag);
194
- container.addEventListener('touchstart', startDrag);
195
 
196
- function startDrag(e) {
197
- isDragging = true;
198
  const touch = e.type === 'touchstart' ? e.touches[0] : e;
199
- dragOffsetX = touch.clientX - containerX;
200
- dragOffsetY = touch.clientY - containerY;
201
- containerVelX = 0;
202
- containerVelY = 0;
203
  e.preventDefault();
204
  }
205
 
@@ -207,24 +273,28 @@
207
  document.addEventListener('touchmove', drag);
208
 
209
  function drag(e) {
210
- if (isDragging) {
211
- const touch = e.type === 'touchmove' ? e.touches[0] : e;
212
- const newX = touch.clientX - dragOffsetX;
213
- const newY = touch.clientY - dragOffsetY;
214
-
215
- containerVelX = (newX - containerX) * 0.5;
216
- containerVelY = (newY - containerY) * 0.5;
217
-
218
- containerX = newX;
219
- containerY = newY;
220
- }
 
 
221
  }
222
 
223
  document.addEventListener('mouseup', stopDrag);
224
  document.addEventListener('touchend', stopDrag);
225
 
226
  function stopDrag() {
227
- isDragging = false;
 
 
228
  }
229
 
230
  // Cập nhật vật lý container
@@ -351,10 +421,19 @@
351
  spiderY = touch.clientY;
352
  });
353
 
354
- // Bỏ qua block autoplay của trình duyệt
355
- document.addEventListener('click', () => {
356
- music.play();
357
- }, { once: true });
 
 
 
 
 
 
 
 
 
358
 
359
  // Di chuyển nhện lớn
360
  function moveSpider() {
 
57
  .container:active {
58
  cursor: grabbing;
59
  }
60
+
61
+ /* Ô mini */
62
+ .mini-box {
63
+ position: absolute;
64
+ border: 3px solid #8B4513;
65
+ padding: 15px;
66
+ border-radius: 12px;
67
+ background-color: rgba(255, 255, 255, 0.25);
68
+ box-shadow: 0 0 15px rgba(0, 0, 0, 0.15);
69
+ overflow: hidden;
70
+ cursor: grab;
71
+ user-select: none;
72
+ width: 120px;
73
+ height: 120px;
74
+ }
75
+
76
+ .mini-box:active {
77
+ cursor: grabbing;
78
+ }
79
 
80
  /* Video nền cho container */
81
  .video-background {
 
181
  </div>
182
 
183
  <div id="spider" class="spider">💗</div>
184
+
185
+ <!-- Ô mini sẽ được tạo động bằng JavaScript -->
186
+
187
  <audio id="bg-music" src="music.mp3" preload="auto"></audio>
188
 
189
  <script>
 
194
  let mouseY = window.innerHeight / 2;
195
  let spiderX = mouseX, spiderY = mouseY;
196
 
197
+ // Mảng chứa tất cả các box (bao gồm cả box chính và mini boxes)
198
+ const boxes = [];
199
+
200
+ // Khởi tạo box chính
201
+ const mainBox = {
202
+ element: container,
203
+ x: window.innerWidth / 2,
204
+ y: window.innerHeight / 2,
205
+ velX: 0,
206
+ velY: 0,
207
+ isDragging: false,
208
+ dragOffsetX: 0,
209
+ dragOffsetY: 0
210
+ };
211
+ boxes.push(mainBox);
212
+
213
+ // Tạo 8 ô mini với video ngẫu nhiên
214
+ const miniBoxCount = 8;
215
+ for (let i = 0; i < miniBoxCount; i++) {
216
+ const miniBox = document.createElement('div');
217
+ miniBox.className = 'mini-box';
218
+
219
+ // Random chọn video
220
+ const videoSrc = Math.random() > 0.5 ? 'video.mp4' : 'Background.mp4';
221
+
222
+ miniBox.innerHTML = `
223
+ <video class="video-background" autoplay loop muted playsinline preload="auto" loading="eager">
224
+ <source src="${videoSrc}" type="video/mp4">
225
+ </video>
226
+ `;
227
+
228
+ document.body.appendChild(miniBox);
229
+
230
+ // Vị trí ngẫu nhiên
231
+ const boxData = {
232
+ element: miniBox,
233
+ x: Math.random() * (window.innerWidth - 150) + 75,
234
+ y: Math.random() * (window.innerHeight - 150) + 75,
235
+ velX: (Math.random() - 0.5) * 5,
236
+ velY: (Math.random() - 0.5) * 5,
237
+ isDragging: false,
238
+ dragOffsetX: 0,
239
+ dragOffsetY: 0
240
+ };
241
+
242
+ boxes.push(boxData);
243
+
244
+ // Thêm event listener cho mini box
245
+ miniBox.addEventListener('mousedown', (e) => startDrag(e, boxData));
246
+ miniBox.addEventListener('touchstart', (e) => startDrag(e, boxData));
247
+ }
248
+
249
  const friction = 0.95;
250
  const elasticity = 0.7;
251
  const wallMargin = 50;
252
 
253
+ // Khởi tạo vị trí ban đầu cho box chính
254
+ mainBox.element.style.left = mainBox.x + 'px';
255
+ mainBox.element.style.top = mainBox.y + 'px';
256
+ mainBox.element.style.transform = 'translate(-50%, -50%)';
257
+
258
+ // Xử lý kéo thả
259
+ container.addEventListener('mousedown', (e) => startDrag(e, mainBox));
260
+ container.addEventListener('touchstart', (e) => startDrag(e, mainBox));
261
 
262
+ function startDrag(e, box) {
263
+ box.isDragging = true;
264
  const touch = e.type === 'touchstart' ? e.touches[0] : e;
265
+ box.dragOffsetX = touch.clientX - box.x;
266
+ box.dragOffsetY = touch.clientY - box.y;
267
+ box.velX = 0;
268
+ box.velY = 0;
269
  e.preventDefault();
270
  }
271
 
 
273
  document.addEventListener('touchmove', drag);
274
 
275
  function drag(e) {
276
+ boxes.forEach(box => {
277
+ if (box.isDragging) {
278
+ const touch = e.type === 'touchmove' ? e.touches[0] : e;
279
+ const newX = touch.clientX - box.dragOffsetX;
280
+ const newY = touch.clientY - box.dragOffsetY;
281
+
282
+ box.velX = (newX - box.x) * 0.5;
283
+ box.velY = (newY - box.y) * 0.5;
284
+
285
+ box.x = newX;
286
+ box.y = newY;
287
+ }
288
+ });
289
  }
290
 
291
  document.addEventListener('mouseup', stopDrag);
292
  document.addEventListener('touchend', stopDrag);
293
 
294
  function stopDrag() {
295
+ boxes.forEach(box => {
296
+ box.isDragging = false;
297
+ });
298
  }
299
 
300
  // Cập nhật vật lý container
 
421
  spiderY = touch.clientY;
422
  });
423
 
424
+ // Bỏ qua block autoplay của trình duyệt - tối ưu âm thanh
425
+ let musicStarted = false;
426
+ function startMusic() {
427
+ if (!musicStarted) {
428
+ music.loop = true;
429
+ music.play().catch(e => console.log('Music autoplay blocked:', e));
430
+ musicStarted = true;
431
+ }
432
+ }
433
+
434
+ document.addEventListener('click', startMusic, { once: true });
435
+ document.addEventListener('touchstart', startMusic, { once: true });
436
+ document.addEventListener('keydown', startMusic, { once: true });
437
 
438
  // Di chuyển nhện lớn
439
  function moveSpider() {