Translsis commited on
Commit
bfa7926
·
verified ·
1 Parent(s): d908df8

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +124 -17
index.html CHANGED
@@ -18,15 +18,18 @@
18
  /* Khung chữ */
19
  .container {
20
  position: absolute;
21
- top: 50%;
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); /* Màu nền trong suốt hơn để thấy video */
28
- box-shadow: 0 0 20px rgba(0, 0, 0, 0.2); /* Hiệu ứng bóng đổ cho khung */
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(); // Chọn ngẫu nhiên emoji
180
  emoji.style.left = `${x}px`;
181
  emoji.style.top = `${y}px`;
182
  document.body.appendChild(emoji);
183
- setTimeout(() => emoji.remove(), 1000); // Xóa emoji sau 1 giây
184
  }
185
 
186
  document.addEventListener('mousemove', (e) => {
187
- mouseX = e.clientX;
188
- mouseY = e.clientY;
189
- createEmoji(e.clientX, e.clientY); // Tạo emoji khi di chuyển chuột
 
 
190
  });
191
 
192
  document.addEventListener('click', (e) => {
193
- createEmoji(e.clientX, e.clientY); // Tạo emoji khi click chuột
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); // Tạo emoji khi vuốt trên màn hình
203
  });
204
 
205
  document.addEventListener('touchstart', (e) => {
206
  const touch = e.touches[0];
207
- createEmoji(touch.clientX, touch.clientY); // Tạo emoji khi chạm vào màn hình
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 (về vị trí cũ nếu không tương tác)
218
  function moveSpider() {
219
  const dx = mouseX - spiderX;
220
  const dy = mouseY - spiderY;
221
- spiderX += dx * 0.2; // Tăng tốc độ di chuyển của nhện
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;