3
3
* 一款简约的相册主题
4
4
* @package 洪墨时光
5
5
* @author zhheo
6
- * @version 2.13
6
+ * @version 2.14
7
7
* @link https://zhheo.com/
8
8
*/
9
9
?>
105
105
<span class="tag-list"><?php $ this ->tags ('' , true ); ?> </span>
106
106
<?php endif ; ?>
107
107
</li>
108
- <!-- 添加所有图片数据到 data 属性 -->
108
+ <!-- 只有当图片数量大于1时才显示面包屑导航 -->
109
+ <?php if (count ($ images ) > 1 ): ?>
109
110
<div class="breadcrumb-nav" data-images='<?php echo json_encode ($ images ); ?> '>
110
111
<?php foreach ($ images as $ index => $ image ): ?>
111
112
<span class="nav-dot <?php echo $ index === 0 ? 'active ' : '' ; ?> " data-index="<?php echo $ index ; ?> "></span>
112
113
<?php endforeach ; ?>
113
114
</div>
115
+ <?php endif ; ?>
114
116
</article>
115
117
<?php endwhile ; ?>
116
118
@@ -246,11 +248,12 @@ function throttle(fn, mustRun = 10) {
246
248
</script>
247
249
<script>
248
250
document.addEventListener('DOMContentLoaded', function() {
249
- let originalWidth, originalHeight;
250
- const imageCache = {}; // 用于缓存图片
251
+ // 创建一个变量来跟踪是否正在切换图片
252
+ let isTransitioning = false;
251
253
252
254
document.addEventListener('mouseover', function(e) {
253
255
if (!e.target.classList.contains('nav-dot')) return;
256
+ if (isTransitioning) return; // 如果正在切换则忽略新的切换请求
254
257
255
258
const nav = e.target.closest('.breadcrumb-nav');
256
259
if (!nav) return;
@@ -262,68 +265,36 @@ function throttle(fn, mustRun = 10) {
262
265
263
266
if (!popup) return;
264
267
265
- // 第一次记录原始尺寸
266
- if (!originalWidth || !originalHeight) {
267
- originalWidth = popup.offsetWidth + 'px';
268
- originalHeight = popup.offsetHeight + 'px';
269
- }
270
-
271
268
const img = popup.querySelector('.pic img');
272
269
if (img) {
273
- // 仅在通过面包屑切换时显示加载动画并保持弹窗尺寸
274
- img.src = '<?php $ this ->options ->themeUrl ('assets/img/loading.gif ' ); ?> ';
275
- img.style.objectFit = 'contain';
276
- img.style.margin = 'auto';
277
- img.style.width = originalWidth;
278
- img.style.height = originalHeight;
279
- }
280
-
281
- // 检查图片是否已缓存
282
- if (!imageCache[images[index]]) {
283
- const newImg = new Image();
284
- newImg.onload = function() {
285
- imageCache[images[index]] = newImg; // 缓存图片
286
- updateImage(popup, newImg, images[index]);
287
- };
288
- newImg.src = images[index] + '<?php $ this ->options ->zmki_sy () ?> ';
289
- } else {
290
- // 如果已缓存,直接使用缓存的图片
291
- updateImage(popup, imageCache[images[index]], images[index]);
270
+ isTransitioning = true;
271
+
272
+ // 确保当前图片有过渡效果
273
+ img.style.transition = 'opacity 0.3s ease-in-out';
274
+ img.style.opacity = '0';
275
+
276
+ // 等待淡出完成
277
+ setTimeout(() => {
278
+ // 切换图片源
279
+ img.src = images[index] + '<?php $ this ->options ->zmki_sy () ?> ';
280
+
281
+ // 图片加载完成后显示
282
+ img.onload = function() {
283
+ img.style.opacity = '1';
284
+ isTransitioning = false;
285
+ };
286
+
287
+ // 如果图片加载失败,也要重置状态
288
+ img.onerror = function() {
289
+ isTransitioning = false;
290
+ };
291
+ }, 300);
292
292
}
293
293
294
294
// 更新导航点状态
295
295
dots.forEach(dot => dot.classList.remove('active'));
296
296
e.target.classList.add('active');
297
297
});
298
-
299
- function updateImage(popup, imgElement, imageUrl) {
300
- const img = popup.querySelector('.pic img');
301
- if (img) {
302
- // 先设置弹窗尺寸为原始尺寸
303
- popup.style.width = originalWidth;
304
- popup.style.height = originalHeight;
305
- popup.style.maxWidth = originalWidth;
306
- popup.style.maxHeight = originalHeight;
307
-
308
- // 设置图片容器样式
309
- const picContainer = popup.querySelector('.pic');
310
- if (picContainer) {
311
- picContainer.style.display = 'flex';
312
- picContainer.style.alignItems = 'center';
313
- picContainer.style.justifyContent = 'center';
314
- picContainer.style.height = '100%';
315
- }
316
-
317
- // 设置图片
318
- img.src = imageUrl + '<?php $ this ->options ->zmki_sy () ?> ';
319
- img.style.maxWidth = '100%';
320
- img.style.maxHeight = '100%';
321
- img.style.width = 'auto';
322
- img.style.height = 'auto';
323
- img.style.objectFit = 'contain';
324
- img.style.margin = 'auto';
325
- }
326
- }
327
298
});
328
299
</script>
329
300
</div>
0 commit comments