Update index.html
Browse files- index.html +124 -17
index.html
CHANGED
|
@@ -18,15 +18,18 @@
|
|
| 18 |
/* Khung chữ */
|
| 19 |
.container {
|
| 20 |
position: absolute;
|
| 21 |
-
|
| 22 |
-
left: 50%;
|
| 23 |
-
transform: translate(-50%, -50%);
|
| 24 |
-
border: 5px solid #8B4513; /* Khung bao quanh chữ */
|
| 25 |
padding: 40px;
|
| 26 |
border-radius: 20px;
|
| 27 |
-
background-color: rgba(255, 255, 255, 0.3);
|
| 28 |
-
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
|
| 29 |
overflow: hidden;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
}
|
| 31 |
|
| 32 |
/* Video nền cho container */
|
|
@@ -130,9 +133,112 @@
|
|
| 130 |
<script>
|
| 131 |
const spider = document.getElementById('spider');
|
| 132 |
const music = document.getElementById('bg-music');
|
|
|
|
| 133 |
let mouseX = window.innerWidth / 2;
|
| 134 |
let mouseY = window.innerHeight / 2;
|
| 135 |
let spiderX = mouseX, spiderY = mouseY;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
// Nhện con (ở các góc màn hình)
|
| 138 |
const babySpiders = [
|
|
@@ -176,21 +282,23 @@
|
|
| 176 |
function createEmoji(x, y) {
|
| 177 |
const emoji = document.createElement('div');
|
| 178 |
emoji.className = 'emoji';
|
| 179 |
-
emoji.innerText = getRandomEmoji();
|
| 180 |
emoji.style.left = `${x}px`;
|
| 181 |
emoji.style.top = `${y}px`;
|
| 182 |
document.body.appendChild(emoji);
|
| 183 |
-
setTimeout(() => emoji.remove(), 1000);
|
| 184 |
}
|
| 185 |
|
| 186 |
document.addEventListener('mousemove', (e) => {
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
|
|
|
|
|
|
| 190 |
});
|
| 191 |
|
| 192 |
document.addEventListener('click', (e) => {
|
| 193 |
-
createEmoji(e.clientX, e.clientY);
|
| 194 |
spiderX = e.clientX;
|
| 195 |
spiderY = e.clientY;
|
| 196 |
});
|
|
@@ -199,12 +307,12 @@
|
|
| 199 |
const touch = e.touches[0];
|
| 200 |
mouseX = touch.clientX;
|
| 201 |
mouseY = touch.clientY;
|
| 202 |
-
createEmoji(mouseX, mouseY);
|
| 203 |
});
|
| 204 |
|
| 205 |
document.addEventListener('touchstart', (e) => {
|
| 206 |
const touch = e.touches[0];
|
| 207 |
-
createEmoji(touch.clientX, touch.clientY);
|
| 208 |
spiderX = touch.clientX;
|
| 209 |
spiderY = touch.clientY;
|
| 210 |
});
|
|
@@ -214,15 +322,14 @@
|
|
| 214 |
music.play();
|
| 215 |
}, { once: true });
|
| 216 |
|
| 217 |
-
// Di chuyển nhện lớn
|
| 218 |
function moveSpider() {
|
| 219 |
const dx = mouseX - spiderX;
|
| 220 |
const dy = mouseY - spiderY;
|
| 221 |
-
spiderX += dx * 0.2;
|
| 222 |
spiderY += dy * 0.2;
|
| 223 |
spider.style.transform = `translate(${spiderX}px, ${spiderY}px)`;
|
| 224 |
|
| 225 |
-
// Nếu không có sự thay đổi lớn trong khoảng thời gian nhất định, nhện sẽ trở về vị trí ban đầu
|
| 226 |
if (Math.abs(dx) < 1 && Math.abs(dy) < 1) {
|
| 227 |
spiderX = window.innerWidth / 2;
|
| 228 |
spiderY = window.innerHeight / 2;
|
|
|
|
| 18 |
/* Khung chữ */
|
| 19 |
.container {
|
| 20 |
position: absolute;
|
| 21 |
+
border: 5px solid #8B4513;
|
|
|
|
|
|
|
|
|
|
| 22 |
padding: 40px;
|
| 23 |
border-radius: 20px;
|
| 24 |
+
background-color: rgba(255, 255, 255, 0.3);
|
| 25 |
+
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
|
| 26 |
overflow: hidden;
|
| 27 |
+
cursor: grab;
|
| 28 |
+
user-select: none;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
.container:active {
|
| 32 |
+
cursor: grabbing;
|
| 33 |
}
|
| 34 |
|
| 35 |
/* Video nền cho container */
|
|
|
|
| 133 |
<script>
|
| 134 |
const spider = document.getElementById('spider');
|
| 135 |
const music = document.getElementById('bg-music');
|
| 136 |
+
const container = document.querySelector('.container');
|
| 137 |
let mouseX = window.innerWidth / 2;
|
| 138 |
let mouseY = window.innerHeight / 2;
|
| 139 |
let spiderX = mouseX, spiderY = mouseY;
|
| 140 |
+
|
| 141 |
+
// Vật lý cho container
|
| 142 |
+
let containerX = window.innerWidth / 2;
|
| 143 |
+
let containerY = window.innerHeight / 2;
|
| 144 |
+
let containerVelX = 0;
|
| 145 |
+
let containerVelY = 0;
|
| 146 |
+
let isDragging = false;
|
| 147 |
+
let dragOffsetX = 0;
|
| 148 |
+
let dragOffsetY = 0;
|
| 149 |
+
const friction = 0.95;
|
| 150 |
+
const elasticity = 0.7;
|
| 151 |
+
const wallMargin = 50;
|
| 152 |
+
|
| 153 |
+
// Khởi tạo vị trí ban đầu
|
| 154 |
+
container.style.left = containerX + 'px';
|
| 155 |
+
container.style.top = containerY + 'px';
|
| 156 |
+
container.style.transform = 'translate(-50%, -50%)';
|
| 157 |
+
|
| 158 |
+
// Xử lý kéo thả container
|
| 159 |
+
container.addEventListener('mousedown', startDrag);
|
| 160 |
+
container.addEventListener('touchstart', startDrag);
|
| 161 |
+
|
| 162 |
+
function startDrag(e) {
|
| 163 |
+
isDragging = true;
|
| 164 |
+
const touch = e.type === 'touchstart' ? e.touches[0] : e;
|
| 165 |
+
dragOffsetX = touch.clientX - containerX;
|
| 166 |
+
dragOffsetY = touch.clientY - containerY;
|
| 167 |
+
containerVelX = 0;
|
| 168 |
+
containerVelY = 0;
|
| 169 |
+
e.preventDefault();
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
document.addEventListener('mousemove', drag);
|
| 173 |
+
document.addEventListener('touchmove', drag);
|
| 174 |
+
|
| 175 |
+
function drag(e) {
|
| 176 |
+
if (isDragging) {
|
| 177 |
+
const touch = e.type === 'touchmove' ? e.touches[0] : e;
|
| 178 |
+
const newX = touch.clientX - dragOffsetX;
|
| 179 |
+
const newY = touch.clientY - dragOffsetY;
|
| 180 |
+
|
| 181 |
+
containerVelX = (newX - containerX) * 0.5;
|
| 182 |
+
containerVelY = (newY - containerY) * 0.5;
|
| 183 |
+
|
| 184 |
+
containerX = newX;
|
| 185 |
+
containerY = newY;
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
document.addEventListener('mouseup', stopDrag);
|
| 190 |
+
document.addEventListener('touchend', stopDrag);
|
| 191 |
+
|
| 192 |
+
function stopDrag() {
|
| 193 |
+
isDragging = false;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
// Cập nhật vật lý container
|
| 197 |
+
function updateContainerPhysics() {
|
| 198 |
+
if (!isDragging) {
|
| 199 |
+
// Áp dụng ma sát
|
| 200 |
+
containerVelX *= friction;
|
| 201 |
+
containerVelY *= friction;
|
| 202 |
+
|
| 203 |
+
// Cập nhật vị trí
|
| 204 |
+
containerX += containerVelX;
|
| 205 |
+
containerY += containerVelY;
|
| 206 |
+
|
| 207 |
+
// Kiểm tra va chạm với tường
|
| 208 |
+
const rect = container.getBoundingClientRect();
|
| 209 |
+
const halfWidth = rect.width / 2;
|
| 210 |
+
const halfHeight = rect.height / 2;
|
| 211 |
+
|
| 212 |
+
// Tường trái
|
| 213 |
+
if (containerX - halfWidth < wallMargin) {
|
| 214 |
+
containerX = wallMargin + halfWidth;
|
| 215 |
+
containerVelX = Math.abs(containerVelX) * elasticity;
|
| 216 |
+
}
|
| 217 |
+
// Tường phải
|
| 218 |
+
if (containerX + halfWidth > window.innerWidth - wallMargin) {
|
| 219 |
+
containerX = window.innerWidth - wallMargin - halfWidth;
|
| 220 |
+
containerVelX = -Math.abs(containerVelX) * elasticity;
|
| 221 |
+
}
|
| 222 |
+
// Tường trên
|
| 223 |
+
if (containerY - halfHeight < wallMargin) {
|
| 224 |
+
containerY = wallMargin + halfHeight;
|
| 225 |
+
containerVelY = Math.abs(containerVelY) * elasticity;
|
| 226 |
+
}
|
| 227 |
+
// Tường dưới
|
| 228 |
+
if (containerY + halfHeight > window.innerHeight - wallMargin) {
|
| 229 |
+
containerY = window.innerHeight - wallMargin - halfHeight;
|
| 230 |
+
containerVelY = -Math.abs(containerVelY) * elasticity;
|
| 231 |
+
}
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
// Cập nhật vị trí DOM
|
| 235 |
+
container.style.left = containerX + 'px';
|
| 236 |
+
container.style.top = containerY + 'px';
|
| 237 |
+
|
| 238 |
+
requestAnimationFrame(updateContainerPhysics);
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
updateContainerPhysics();
|
| 242 |
|
| 243 |
// Nhện con (ở các góc màn hình)
|
| 244 |
const babySpiders = [
|
|
|
|
| 282 |
function createEmoji(x, y) {
|
| 283 |
const emoji = document.createElement('div');
|
| 284 |
emoji.className = 'emoji';
|
| 285 |
+
emoji.innerText = getRandomEmoji();
|
| 286 |
emoji.style.left = `${x}px`;
|
| 287 |
emoji.style.top = `${y}px`;
|
| 288 |
document.body.appendChild(emoji);
|
| 289 |
+
setTimeout(() => emoji.remove(), 1000);
|
| 290 |
}
|
| 291 |
|
| 292 |
document.addEventListener('mousemove', (e) => {
|
| 293 |
+
if (!isDragging) {
|
| 294 |
+
mouseX = e.clientX;
|
| 295 |
+
mouseY = e.clientY;
|
| 296 |
+
createEmoji(e.clientX, e.clientY);
|
| 297 |
+
}
|
| 298 |
});
|
| 299 |
|
| 300 |
document.addEventListener('click', (e) => {
|
| 301 |
+
createEmoji(e.clientX, e.clientY);
|
| 302 |
spiderX = e.clientX;
|
| 303 |
spiderY = e.clientY;
|
| 304 |
});
|
|
|
|
| 307 |
const touch = e.touches[0];
|
| 308 |
mouseX = touch.clientX;
|
| 309 |
mouseY = touch.clientY;
|
| 310 |
+
createEmoji(mouseX, mouseY);
|
| 311 |
});
|
| 312 |
|
| 313 |
document.addEventListener('touchstart', (e) => {
|
| 314 |
const touch = e.touches[0];
|
| 315 |
+
createEmoji(touch.clientX, touch.clientY);
|
| 316 |
spiderX = touch.clientX;
|
| 317 |
spiderY = touch.clientY;
|
| 318 |
});
|
|
|
|
| 322 |
music.play();
|
| 323 |
}, { once: true });
|
| 324 |
|
| 325 |
+
// Di chuyển nhện lớn
|
| 326 |
function moveSpider() {
|
| 327 |
const dx = mouseX - spiderX;
|
| 328 |
const dy = mouseY - spiderY;
|
| 329 |
+
spiderX += dx * 0.2;
|
| 330 |
spiderY += dy * 0.2;
|
| 331 |
spider.style.transform = `translate(${spiderX}px, ${spiderY}px)`;
|
| 332 |
|
|
|
|
| 333 |
if (Math.abs(dx) < 1 && Math.abs(dy) < 1) {
|
| 334 |
spiderX = window.innerWidth / 2;
|
| 335 |
spiderY = window.innerHeight / 2;
|