Skip to content

Commit 33bbf15

Browse files
committed
feat: Enhance image gallery with modal functionality and improved styles in index.html
1 parent 4ec22fc commit 33bbf15

File tree

1 file changed

+128
-5
lines changed

1 file changed

+128
-5
lines changed

waimai/index.html

Lines changed: 128 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,72 @@
6161
padding: 30px;
6262
box-shadow: 0 8px 32px rgba(0,0,0,0.1);
6363
backdrop-filter: blur(10px);
64+
display: flex;
65+
flex-wrap: wrap;
66+
justify-content: center;
67+
gap: 20px;
6468
}
6569

6670
.trophy-image {
67-
max-width: 100%;
68-
height: auto;
71+
width: 200px;
72+
height: 200px;
73+
object-fit: cover;
6974
border-radius: 15px;
7075
box-shadow: 0 8px 25px rgba(0,0,0,0.2);
76+
cursor: pointer;
77+
transition: transform 0.3s ease, box-shadow 0.3s ease;
78+
}
79+
80+
.trophy-image:hover {
81+
transform: scale(1.05);
82+
box-shadow: 0 12px 30px rgba(0,0,0,0.3);
83+
}
84+
85+
/* 模态框样式 */
86+
.modal {
87+
display: none;
88+
position: fixed;
89+
z-index: 1000;
90+
left: 0;
91+
top: 0;
92+
width: 100%;
93+
height: 100%;
94+
background-color: rgba(0,0,0,0.8);
95+
backdrop-filter: blur(5px);
96+
}
97+
98+
.modal-content {
99+
position: absolute;
100+
top: 50%;
101+
left: 50%;
102+
transform: translate(-50%, -50%);
103+
max-width: 90%;
104+
max-height: 90%;
105+
border-radius: 15px;
106+
box-shadow: 0 20px 60px rgba(0,0,0,0.5);
107+
}
108+
109+
.modal-image {
110+
width: 100%;
111+
height: 100%;
112+
object-fit: contain;
113+
border-radius: 15px;
114+
}
115+
116+
.close {
117+
position: absolute;
118+
top: 15px;
119+
right: 25px;
120+
color: white;
121+
font-size: 35px;
122+
font-weight: bold;
123+
cursor: pointer;
124+
z-index: 1001;
125+
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
126+
}
127+
128+
.close:hover {
129+
color: #ff6b6b;
71130
}
72131

73132
.contribute-section {
@@ -111,6 +170,27 @@
111170
padding: 12px 24px;
112171
font-size: 1rem;
113172
}
173+
174+
.trophy-image {
175+
width: 150px;
176+
height: 150px;
177+
}
178+
179+
.image-section {
180+
gap: 15px;
181+
padding: 20px;
182+
}
183+
184+
.modal-content {
185+
max-width: 95%;
186+
max-height: 95%;
187+
}
188+
189+
.close {
190+
font-size: 30px;
191+
top: 10px;
192+
right: 20px;
193+
}
114194
}
115195
</style>
116196
</head>
@@ -134,12 +214,20 @@ <h2>自2025/09/01起</h2>
134214
</div>
135215
<br><br><br>
136216
<div class="image-section"><!--PR请在项目添加png然后按照格式命名引用-->
137-
<img src="oops1.png" alt="外卖被收走现场" class="trophy-image">
138-
<img src="oops2.png" alt="外卖被收走现场" class="trophy-image">
139-
<img src="oops3.png" alt="外卖被收走现场" class="trophy-image">
217+
<img src="oops1.png" alt="外卖被收走现场" class="trophy-image" onclick="openModal(this)">
218+
<img src="oops2.png" alt="外卖被收走现场" class="trophy-image" onclick="openModal(this)">
219+
<img src="oops3.png" alt="外卖被收走现场" class="trophy-image" onclick="openModal(this)">
140220
</div><!--PR请在项目添加png然后按照格式命名引用-->
141221
</div>
142222

223+
<!-- 模态框 -->
224+
<div id="imageModal" class="modal">
225+
<span class="close" onclick="closeModal()">&times;</span>
226+
<div class="modal-content">
227+
<img id="modalImage" class="modal-image" src="" alt="">
228+
</div>
229+
</div>
230+
143231
<script>
144232
// 随机标题数组
145233
const titles = [
@@ -154,6 +242,41 @@ <h2>自2025/09/01起</h2>
154242
document.getElementById('random-title').textContent = titles[randomIndex];
155243
}
156244

245+
// 打开模态框
246+
function openModal(img) {
247+
const modal = document.getElementById('imageModal');
248+
const modalImg = document.getElementById('modalImage');
249+
modal.style.display = 'block';
250+
modalImg.src = img.src;
251+
modalImg.alt = img.alt;
252+
253+
// 防止背景滚动
254+
document.body.style.overflow = 'hidden';
255+
}
256+
257+
// 关闭模态框
258+
function closeModal() {
259+
const modal = document.getElementById('imageModal');
260+
modal.style.display = 'none';
261+
262+
// 恢复背景滚动
263+
document.body.style.overflow = 'auto';
264+
}
265+
266+
// 点击模态框背景关闭
267+
document.getElementById('imageModal').addEventListener('click', function(e) {
268+
if (e.target === this) {
269+
closeModal();
270+
}
271+
});
272+
273+
// ESC键关闭模态框
274+
document.addEventListener('keydown', function(e) {
275+
if (e.key === 'Escape') {
276+
closeModal();
277+
}
278+
});
279+
157280
// 页面加载时设置随机标题
158281
document.addEventListener('DOMContentLoaded', function() {
159282
setRandomTitle();

0 commit comments

Comments
 (0)