cwadayi commited on
Commit
da47862
·
verified ·
1 Parent(s): 9eb7d90

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +30 -1
script.js CHANGED
@@ -35,11 +35,40 @@ document.addEventListener('DOMContentLoaded', () => {
35
  }
36
  });
37
  }, {
38
- rootMargin: '-50% 0px -50% 0px' // 觸發區域設定在螢幕正中央
39
  });
40
  sections.forEach(section => {
41
  if(section.id) {
42
  navObserver.observe(section);
43
  }
44
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  });
 
35
  }
36
  });
37
  }, {
38
+ rootMargin: '-50% 0px -50% 0px'
39
  });
40
  sections.forEach(section => {
41
  if(section.id) {
42
  navObserver.observe(section);
43
  }
44
  });
45
+
46
+ // --- ★★★★★ 新增:點擊放大 (Lightbox) 功能 ★★★★★ ---
47
+ const lightboxTriggers = document.querySelectorAll('.lightbox-trigger');
48
+
49
+ lightboxTriggers.forEach(trigger => {
50
+ trigger.addEventListener('click', function(e) {
51
+ e.preventDefault(); // 防止連結跳轉
52
+
53
+ const imageUrl = this.getAttribute('href');
54
+
55
+ // 創建燈箱
56
+ const lightbox = document.createElement('div');
57
+ lightbox.classList.add('lightbox');
58
+
59
+ const lightboxContent = document.createElement('img');
60
+ lightboxContent.src = imageUrl;
61
+
62
+ lightbox.appendChild(lightboxContent);
63
+ document.body.appendChild(lightbox);
64
+
65
+ // 點擊燈箱關閉
66
+ lightbox.addEventListener('click', () => {
67
+ lightbox.classList.add('closing');
68
+ setTimeout(() => {
69
+ document.body.removeChild(lightbox);
70
+ }, 300); // 等待動畫結束後移除
71
+ });
72
+ });
73
+ });
74
  });