Update index.html
Browse files- index.html +54 -47
index.html
CHANGED
|
@@ -181,9 +181,6 @@
|
|
| 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>
|
|
@@ -297,52 +294,59 @@
|
|
| 297 |
});
|
| 298 |
}
|
| 299 |
|
| 300 |
-
// Cập nhật vật lý
|
| 301 |
-
function
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
}
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
}
|
| 336 |
-
}
|
| 337 |
-
|
| 338 |
-
// Cập nhật vị trí DOM
|
| 339 |
-
container.style.left = containerX + 'px';
|
| 340 |
-
container.style.top = containerY + 'px';
|
| 341 |
|
| 342 |
-
requestAnimationFrame(
|
| 343 |
}
|
| 344 |
|
| 345 |
-
|
| 346 |
|
| 347 |
// Nhện con (ở các góc màn hình)
|
| 348 |
const babySpiders = [
|
|
@@ -394,9 +398,12 @@
|
|
| 394 |
}
|
| 395 |
|
| 396 |
document.addEventListener('mousemove', (e) => {
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
|
|
|
|
|
|
|
|
|
| 400 |
createEmoji(e.clientX, e.clientY);
|
| 401 |
}
|
| 402 |
});
|
|
|
|
| 181 |
</div>
|
| 182 |
|
| 183 |
<div id="spider" class="spider">💗</div>
|
|
|
|
|
|
|
|
|
|
| 184 |
<audio id="bg-music" src="music.mp3" preload="auto"></audio>
|
| 185 |
|
| 186 |
<script>
|
|
|
|
| 294 |
});
|
| 295 |
}
|
| 296 |
|
| 297 |
+
// Cập nhật vật lý cho tất cả boxes
|
| 298 |
+
function updateBoxPhysics() {
|
| 299 |
+
boxes.forEach(box => {
|
| 300 |
+
if (!box.isDragging) {
|
| 301 |
+
// Áp dụng ma sát
|
| 302 |
+
box.velX *= friction;
|
| 303 |
+
box.velY *= friction;
|
| 304 |
+
|
| 305 |
+
// Cập nhật vị trí
|
| 306 |
+
box.x += box.velX;
|
| 307 |
+
box.y += box.velY;
|
| 308 |
+
|
| 309 |
+
// Kiểm tra va chạm với tường
|
| 310 |
+
const rect = box.element.getBoundingClientRect();
|
| 311 |
+
const halfWidth = rect.width / 2;
|
| 312 |
+
const halfHeight = rect.height / 2;
|
| 313 |
+
|
| 314 |
+
// Tường trái
|
| 315 |
+
if (box.x - halfWidth < wallMargin) {
|
| 316 |
+
box.x = wallMargin + halfWidth;
|
| 317 |
+
box.velX = Math.abs(box.velX) * elasticity;
|
| 318 |
+
}
|
| 319 |
+
// Tường phải
|
| 320 |
+
if (box.x + halfWidth > window.innerWidth - wallMargin) {
|
| 321 |
+
box.x = window.innerWidth - wallMargin - halfWidth;
|
| 322 |
+
box.velX = -Math.abs(box.velX) * elasticity;
|
| 323 |
+
}
|
| 324 |
+
// Tường trên
|
| 325 |
+
if (box.y - halfHeight < wallMargin) {
|
| 326 |
+
box.y = wallMargin + halfHeight;
|
| 327 |
+
box.velY = Math.abs(box.velY) * elasticity;
|
| 328 |
+
}
|
| 329 |
+
// Tường dưới
|
| 330 |
+
if (box.y + halfHeight > window.innerHeight - wallMargin) {
|
| 331 |
+
box.y = window.innerHeight - wallMargin - halfHeight;
|
| 332 |
+
box.velY = -Math.abs(box.velY) * elasticity;
|
| 333 |
+
}
|
| 334 |
}
|
| 335 |
+
|
| 336 |
+
// Cập nhật vị trí DOM
|
| 337 |
+
if (box.element === container) {
|
| 338 |
+
box.element.style.left = box.x + 'px';
|
| 339 |
+
box.element.style.top = box.y + 'px';
|
| 340 |
+
} else {
|
| 341 |
+
box.element.style.left = (box.x - 60) + 'px';
|
| 342 |
+
box.element.style.top = (box.y - 60) + 'px';
|
| 343 |
}
|
| 344 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
+
requestAnimationFrame(updateBoxPhysics);
|
| 347 |
}
|
| 348 |
|
| 349 |
+
updateBoxPhysics();
|
| 350 |
|
| 351 |
// Nhện con (ở các góc màn hình)
|
| 352 |
const babySpiders = [
|
|
|
|
| 398 |
}
|
| 399 |
|
| 400 |
document.addEventListener('mousemove', (e) => {
|
| 401 |
+
mouseX = e.clientX;
|
| 402 |
+
mouseY = e.clientY;
|
| 403 |
+
|
| 404 |
+
// Chỉ tạo emoji khi không kéo box nào
|
| 405 |
+
const anyDragging = boxes.some(box => box.isDragging);
|
| 406 |
+
if (!anyDragging) {
|
| 407 |
createEmoji(e.clientX, e.clientY);
|
| 408 |
}
|
| 409 |
});
|