Lashtw commited on
Commit
938bb2b
·
verified ·
1 Parent(s): da86c33

Upload 40 files

Browse files
Files changed (2) hide show
  1. tower.html +4 -19
  2. tower.js +24 -8
tower.html CHANGED
@@ -170,6 +170,7 @@
170
  vertical-align: middle;
171
  transition: all 0.3s;
172
  touch-action: none;
 
173
  }
174
 
175
  .drop-zone.filled {
@@ -209,6 +210,7 @@
209
  z-index: 10;
210
  will-change: transform;
211
  touch-action: none;
 
212
  }
213
 
214
  .drag-item:hover {
@@ -395,6 +397,7 @@
395
  .sortable-container {
396
  min-height: 40px;
397
  touch-action: none;
 
398
  }
399
 
400
  .sortable-fallback {
@@ -521,25 +524,7 @@
521
  </div>
522
  </div>
523
  </div>
524
-
525
- <script src="tower.js"></script>
526
 
527
- <!-- 音樂連續播放控制 -->
528
- <script>
529
- document.addEventListener('DOMContentLoaded', function() {
530
- const bgmAudio = document.getElementById('bgm');
531
- const toggleBgmBtn = document.getElementById('toggle-bgm');
532
-
533
- // 從localStorage獲取音樂播放狀態
534
- const musicPlaying = localStorage.getItem('towerMusicPlaying');
535
-
536
- if (musicPlaying === 'true') {
537
- bgmAudio.play().catch(e => console.log('自動播放被阻止:', e));
538
- toggleBgmBtn.textContent = '音樂關';
539
- } else {
540
- toggleBgmBtn.textContent = '音樂開';
541
- }
542
- });
543
- </script>
544
  </body>
545
  </html>
 
170
  vertical-align: middle;
171
  transition: all 0.3s;
172
  touch-action: none;
173
+ will-change: transform;
174
  }
175
 
176
  .drop-zone.filled {
 
210
  z-index: 10;
211
  will-change: transform;
212
  touch-action: none;
213
+ -webkit-tap-highlight-color: transparent;
214
  }
215
 
216
  .drag-item:hover {
 
397
  .sortable-container {
398
  min-height: 40px;
399
  touch-action: none;
400
+ will-change: transform;
401
  }
402
 
403
  .sortable-fallback {
 
524
  </div>
525
  </div>
526
  </div>
 
 
527
 
528
+ <script src="tower.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
529
  </body>
530
  </html>
tower.js CHANGED
@@ -390,8 +390,8 @@ document.addEventListener('DOMContentLoaded', function() {
390
  parent.classList.remove('filled');
391
  parent.style.backgroundColor = 'rgba(100, 100, 100, 0.5)';
392
 
393
- // 元素移回拖拽項容器
394
- dragItemsContainer.appendChild(this);
395
 
396
  // 更新保存的答案
397
  updateSavedAnswers();
@@ -406,7 +406,7 @@ document.addEventListener('DOMContentLoaded', function() {
406
  const dragItemsSortable = new Sortable(dragItemsContainer, {
407
  group: {
408
  name: 'formula',
409
- pull: true,
410
  put: true
411
  },
412
  animation: 100,
@@ -422,6 +422,25 @@ document.addEventListener('DOMContentLoaded', function() {
422
  },
423
  onEnd: function(evt) {
424
  evt.item.style.opacity = '1';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
425
  }
426
  });
427
 
@@ -445,8 +464,8 @@ document.addEventListener('DOMContentLoaded', function() {
445
  parent.classList.remove('filled');
446
  parent.style.backgroundColor = 'rgba(100, 100, 100, 0.5)';
447
 
448
- // 元素移回拖拽項容器
449
- dragItemsContainer.appendChild(this);
450
 
451
  // 更新保存的答案
452
  updateSavedAnswers();
@@ -457,9 +476,6 @@ document.addEventListener('DOMContentLoaded', function() {
457
  dropZones[index].appendChild(clonedItem);
458
  dropZones[index].classList.add('filled');
459
  dropZones[index].style.backgroundColor = 'rgba(255, 140, 0, 0.3)';
460
-
461
- // 從原始拖拽項容器中移除
462
- dragItem.remove();
463
  }
464
  }
465
  });
 
390
  parent.classList.remove('filled');
391
  parent.style.backgroundColor = 'rgba(100, 100, 100, 0.5)';
392
 
393
+ // 移除元素
394
+ this.remove();
395
 
396
  // 更新保存的答案
397
  updateSavedAnswers();
 
406
  const dragItemsSortable = new Sortable(dragItemsContainer, {
407
  group: {
408
  name: 'formula',
409
+ pull: 'clone', // 設置為clone模式,拖拽時複製元素
410
  put: true
411
  },
412
  animation: 100,
 
422
  },
423
  onEnd: function(evt) {
424
  evt.item.style.opacity = '1';
425
+ },
426
+ // 當元素被複製時
427
+ onClone: function(evt) {
428
+ const clone = evt.clone;
429
+
430
+ // 為複製的元素添加點擊事件,點擊可移除(如果在拖放區內)
431
+ clone.addEventListener('click', function() {
432
+ const parent = this.parentElement;
433
+ if (parent && parent.classList.contains('drop-zone')) {
434
+ parent.classList.remove('filled');
435
+ parent.style.backgroundColor = 'rgba(100, 100, 100, 0.5)';
436
+
437
+ // 移除元素
438
+ this.remove();
439
+
440
+ // 更新保存的答案
441
+ updateSavedAnswers();
442
+ }
443
+ });
444
  }
445
  });
446
 
 
464
  parent.classList.remove('filled');
465
  parent.style.backgroundColor = 'rgba(100, 100, 100, 0.5)';
466
 
467
+ // 移除元素
468
+ this.remove();
469
 
470
  // 更新保存的答案
471
  updateSavedAnswers();
 
476
  dropZones[index].appendChild(clonedItem);
477
  dropZones[index].classList.add('filled');
478
  dropZones[index].style.backgroundColor = 'rgba(255, 140, 0, 0.3)';
 
 
 
479
  }
480
  }
481
  });