-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwedding-img.html
More file actions
835 lines (742 loc) · 32.4 KB
/
wedding-img.html
File metadata and controls
835 lines (742 loc) · 32.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>图片对比工具</title>
<style>
/* 通用按钮样式 */
button {
padding: 10px 20px;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
outline: none;
}
.image-group {
margin: 20px;
}
.image-pair {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
.image-container {
position: relative;
overflow: hidden;
width: 49%;
box-sizing: border-box;
}
.image-container img {
border: 2px solid rgb(107, 106, 106);
box-sizing: border-box;
cursor: pointer;
position: relative;
transition: transform 0.3s ease;
min-width: 100%;
max-width: 100%;
height: auto;
}
.single-image img {
border: 2px solid rgb(107, 106, 106);
box-sizing: border-box;
cursor: pointer;
position: relative;
transition: transform 0.3s ease;
min-width: 100%;
max-width: 100%;
height: auto;
}
.controls {
margin-top: 10px;
}
button {
margin-right: 10px;
}
/* 主操作按钮样式 */
.controls button {
margin-bottom: 10px;
background-color: #007BFF;
color: white;
}
.controls button:hover {
background-color: #0056b3;
}
.image-group-list-box {
position: relative;
max-width: 100%;
padding-left: 10px;
overflow: auto;
}
.image-group-list {
display: flex;
flex-wrap: nowrap;
box-sizing: border-box;
}
.image-group-list img {
max-width: 64px;
max-height: 64px;
margin-right: 6px;
margin-top: 6px;
height: auto;
cursor: pointer;
border: 2px solid rgb(107, 106, 106);
box-sizing: border-box;
}
.popup {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
z-index: 1000;
}
.popup-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 15px;
min-width: 90vw;
max-width: 90vw;
min-height: 90vh;
max-height: 90vh;
overflow: hidden;
/* 新增样式,设置相对定位 */
position: relative;
}
.close {
font-size: 24px;
font-weight: bold;
color: #333;
background: none;
position: absolute;
top: 10px;
right: 10px;
cursor: pointer;
z-index: 1001;
transition: color 0.3s ease;
}
.close:hover {
color: #dc3545;
}
.compare-btn,
.old-btn,
.reset-btn {
background-color: #28a745;
color: white;
position: absolute;
top: 10px;
left: 10px;
z-index: 1001;
display: none;
/* 默认隐藏对比按钮 */
}
.compare-btn:hover,
.old-btn:hover,
.reset-btn:hover {
background-color: #218838;
}
.old-btn {
left: 100px;
}
.reset-btn {
left: 220px;
display: block;
}
#originalImage1,
#originalImage2 {
max-width: 100%;
max-height: 100%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(1);
/* 使图片居中并初始缩放为 1 */
transform-origin: center center;
/* 设置缩放中心点为图片中心 */
transition: transform 0.3s ease, opacity 0.3s ease;
}
#originalImage2 {
z-index: 1;
/* 让第二张图覆盖第一张图 */
}
@media screen and (max-width: 767px) {
button {
padding: 4px 4px;
border: none;
border-radius: 5px;
font-size: 12px;
cursor: pointer;
transition: background-color 0.3s ease;
outline: none;
}
.image-container {
overflow: hidden;
width: 85%;
}
}
</style>
</head>
<body>
点击下列缩略图跳转指定图片
<div class="image-group-list-box">
<div class="image-group-list" id="imageGroupList">
</div>
</div>
<div class="image-group" id="currentImageGroup">
<div class="controls">
<button onclick="prevGroup()">上一组</button>
<button onclick="nextGroup()">下一组</button>
</div>
<div class="controls">
<button onclick="zoomIn()">放大</button>
<button onclick="zoomOut()">缩小</button>
<button onclick="resetZoom()">复原</button>
<button onclick="showOriginalImage()">查看原图(双击图片)</button>
</div>
<h2 id="groupTitle"></h2>
<div class="image-pair" id="imagePair"></div>
<div class="single-image" id="singleImage"></div>
</div>
<div class="popup" id="popup">
<div class="popup-content">
<span class="close" onclick="closePopup()">×</span>
<!-- 新增对比按钮 -->
<button class="compare-btn" onclick="toggleCompare()" style="display: none;" title="透明度50%">对比(半透)</button>
<button class="old-btn" onclick="oldPopup()" style="display: none;" title="透明度100%">切换原片(全透)</button>
<button class="reset-btn" onclick="resetPopup()">复原</button>
<img id="originalImage1" src="" alt="Original Image 1">
<img id="originalImage2" src="" alt="Original Image 2">
</div>
</div>
<script>
const imageUrlsOld = [
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF7995.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8019.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8027.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8032.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8060.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8066.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8082.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8162.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8222.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8233.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8242.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8277.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8300.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8317.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8340.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8365.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8367.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8380.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8387.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/DSCF8421.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990002.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990003.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990008.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990010.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990014.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990015.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990021.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990027.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990041.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990048.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990056.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990060.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990061.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990064.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990066.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097059/TY990070.jpg",
// 添加更多图片 URL
];
// 假设你有一个图片URL的数组
var imageUrls = [
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990066.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990064.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8380.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990061.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990056.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990060.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990048.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990027.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990010.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990008.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990002.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8365.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990041.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990021.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990015.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990014.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990003.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8421.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8387.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8367.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8340.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8300.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8242.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8317.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8277.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8066.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8019.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF7995.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8060.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8032.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8027.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8233.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8162.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8082.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990070.jpg",
"https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/DSCF8222.jpg",
];
let imageGMap = {
}
const fileNameRegex = /[^\/?#]+(?=[?#]|$)/;
imageUrlsOld.forEach(u => {
const match = u.match(fileNameRegex)
const fileName = match ? match[0] : null;
if (fileName) {
imageGMap[fileName] = imageGMap[fileName] || {}
imageGMap[fileName].old = u
}
})
imageUrls.forEach(u => {
const match = u.match(fileNameRegex)
const fileName = match ? match[0] : null;
if (fileName) {
imageGMap[fileName] = imageGMap[fileName] || {}
imageGMap[fileName].url = u
}
})
let imageGroups = [
{
title: "海报P001.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097061/P001.jpg"]
},
{
title: "1中框40x40cm-1.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097057/1%E4%B8%AD%E6%A1%8640x40cm-1.jpg"]
},
{
title: "1中框40x40cm-2.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097057/1%E4%B8%AD%E6%A1%8640x40cm-2.jpg"]
},
{
title: "1主框60x90cm.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097057/1%E4%B8%BB%E6%A1%8660x90cm.jpg"]
},
{
title: "1摆台18x23cm.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097057/1%E6%91%86%E5%8F%B018x23cm.jpg"]
},
{
title: "1摆台23x18cm.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097057/1%E6%91%86%E5%8F%B023x18cm.jpg"]
},
{
title: "P001.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097056/P001.jpg"]
},
{
title: "P002.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097056/P002.jpg"]
}
,
{
title: "P003.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097056/P003.jpg"]
}
,
{
title: "P004.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097056/P004.jpg"]
}
,
{
title: "P005.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097056/P005.jpg"]
}
,
{
title: "P006.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097056/P006.jpg"]
},
{
title: "P007.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097056/P007.jpg"]
},
{
title: "P008.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097056/P008.jpg"]
},
{
title: "P009.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097056/P009.jpg"]
},
{
title: "P010.jpg",
images: ["https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1097056/P010.jpg"]
}
]
Object.keys(imageGMap).forEach((key) => {
imageGroups.push({ title: key, images: [imageGMap[key].old, imageGMap[key].url] })
})
let currentIndex = 0;
let scale = 1;
let translateX = [0, 0];
let translateY = [0, 0];
let isDragging = [false, false];
let startX = [0, 0];
let startY = [0, 0];
let startTranslateX = [0, 0];
let startTranslateY = [0, 0];
imageGroups.forEach((item, idx) => {
const imageGroupsListID = document.getElementById('imageGroupList');
const img1 = document.createElement('img');
let imgSrc = item.images.length > 1 ? item.images[1] : item.images[0];
img1.dataset.src = item.images[0];
img1.src = imgSrc + '!w320';
img1.title = item.title;
img1.alt = `Image 1 of ${item.title}`;
img1.onclick = () => {
currentIndex = idx;
displayGroup();
};
imageGroupsListID.appendChild(img1);
});
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
const realSrc = img.dataset.src;
const imgObj = new Image();
imgObj.src = realSrc;
imgObj.onload = () => {
img.src = realSrc;
observer.unobserve(img);
};
}
});
});
function displayGroup() {
const currentGroup = imageGroups[currentIndex];
const groupTitle = document.getElementById('groupTitle');
const imagePair = document.getElementById('imagePair');
const singleImage = document.getElementById('singleImage');
groupTitle.textContent = currentGroup.title;
imagePair.innerHTML = '';
singleImage.innerHTML = '';
if (currentGroup.images.length === 2) {
const container1 = document.createElement('div');
container1.className = 'image-container';
const img1 = document.createElement('img');
img1.dataset.src = currentGroup.images[0];
img1.src = currentGroup.images[0] + '!w320';
img1.alt = `Image 1 of ${currentGroup.title}`;
img1.id = 'image1';
// 添加双击事件监听器
img1.ondblclick = () => {
showOriginalImage();
};
container1.appendChild(img1);
observer.observe(img1);
const container2 = document.createElement('div');
container2.className = 'image-container';
const img2 = document.createElement('img');
img2.dataset.src = currentGroup.images[1];
img2.src = currentGroup.images[1] + '!w320';
img2.alt = `Image 2 of ${currentGroup.title}`;
img2.id = 'image2';
// 添加双击事件监听器
img2.ondblclick = () => {
showOriginalImage();
};
container2.appendChild(img2);
observer.observe(img2);
imagePair.appendChild(container1);
imagePair.appendChild(container2);
} else if (currentGroup.images.length === 1) {
const img = document.createElement('img');
img.dataset.src = currentGroup.images[0];
img.src = currentGroup.images[0] + '!w320';
img.alt = `Single Image of ${currentGroup.title}`;
// 添加双击事件监听器
img.ondblclick = () => {
showOriginalImage();
};
singleImage.appendChild(img);
observer.observe(img);
}
}
function prevGroup() {
currentIndex = (currentIndex - 1 + imageGroups.length) % imageGroups.length;
displayGroup();
}
function nextGroup() {
currentIndex = (currentIndex + 1) % imageGroups.length;
displayGroup();
}
function syncScroll() {
const image1 = document.getElementById('image1');
const image2 = document.getElementById('image2');
if (image1 && image2) {
image1.removeEventListener('scroll', syncScrollHandler);
image2.removeEventListener('scroll', syncScrollHandler);
function syncScrollHandler() {
image2.scrollTop = image1.scrollTop;
image2.scrollLeft = image1.scrollLeft;
}
image1.addEventListener('scroll', syncScrollHandler);
image2.addEventListener('scroll', syncScrollHandler);
}
}
function zoomIn() {
scale += 0.1;
applyZoom();
}
function zoomOut() {
scale = Math.max(0.1, scale - 0.1);
applyZoom();
}
function resetZoom() {
scale = 1;
translateX = [0, 0];
translateY = [0, 0];
applyZoom();
}
function applyZoom() {
const image1 = document.getElementById('image1');
const image2 = document.getElementById('image2');
if (image1) {
image1.style.transform = `scale(${scale}) translate(${translateX[0]}px, ${translateY[0]}px)`;
}
if (image2) {
image2.style.transform = `scale(${scale}) translate(${translateX[1]}px, ${translateY[1]}px)`;
}
}
// 弹窗图片的缩放、位置和拖动状态
let popupScale = 1;
let popupTranslateX = 0;
let popupTranslateY = 0;
let isPopupDragging = false;
let popupStartX = 0;
let popupStartY = 0;
let popupStartTranslateX = 0;
let popupStartTranslateY = 0;
let isPinching = false;
let startDistance = 0;
let startScale = 0;
// 新增:定义灵敏度基础值和调节系数
const BASE_SENSITIVITY = 1;
const SENSITIVITY_ADJUSTMENT = 0.2;
function showOriginalImage() {
const currentGroup = imageGroups[currentIndex];
const popup = document.getElementById('popup');
const originalImage1 = document.getElementById('originalImage1');
const originalImage2 = document.getElementById('originalImage2');
const compareBtn = document.querySelector('.compare-btn');
const oldBtn = document.querySelector('.old-btn');
if (currentGroup.images.length > 0) {
originalImage1.src = currentGroup.images[0];
if (currentGroup.images.length > 1) {
originalImage2.style.display = "block"
originalImage2.src = currentGroup.images[1];
compareBtn.style.display = 'block';
oldBtn.style.display = 'block';
} else {
originalImage2.style.display = "none"
compareBtn.style.display = 'none';
oldBtn.style.display = 'none';
}
// 重置弹窗图片的缩放和位置
popupScale = 1;
popupTranslateX = 0;
popupTranslateY = 0;
applyPopupZoom();
originalImage2.style.opacity = 1;
popup.style.display = 'block';
disablePageZoom()
}
}
function disablePageZoom() {
const metaViewport = document.querySelector('meta[name="viewport"]');
if (metaViewport) {
metaViewport.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';
}
}
function enablePageZoom() {
const metaViewport = document.querySelector('meta[name="viewport"]');
if (metaViewport) {
metaViewport.content = 'width=device-width, initial-scale=1.0';
}
}
function resetPopup() {
// 重置弹窗图片的缩放和位置
popupScale = 1;
popupTranslateX = 0;
popupTranslateY = 0;
applyPopupZoom();
originalImage2.style.opacity = 1;
}
function toggleCompare() {
const originalImage2 = document.getElementById('originalImage2');
let opacity = parseFloat(originalImage2.style.opacity);
if (isNaN(opacity) || opacity === 1) {
originalImage2.style.opacity = 0.5;
} else {
originalImage2.style.opacity = 1;
}
}
function oldPopup() {
const originalImage2 = document.getElementById('originalImage2');
let opacity = parseFloat(originalImage2.style.opacity);
if (isNaN(opacity) || opacity === 1) {
originalImage2.style.opacity = 0;
} else {
originalImage2.style.opacity = 1;
}
}
function closePopup() {
const popup = document.getElementById('popup');
popup.style.display = 'none';
// 恢复页面缩放
enablePageZoom();
}
// 弹窗图片放大
function popupZoomIn() {
popupScale += 0.1;
applyPopupZoom();
}
// 弹窗图片缩小
function popupZoomOut() {
popupScale = Math.max(0.1, popupScale - 0.1);
applyPopupZoom();
}
function applyPopupZoom() {
const originalImage1 = document.getElementById('originalImage1');
const originalImage2 = document.getElementById('originalImage2');
if (originalImage1) {
originalImage1.style.transform = `translate(-50%, -50%) scale(${popupScale}) translate(${popupTranslateX}px, ${popupTranslateY}px)`;
}
if (originalImage2) {
originalImage2.style.transform = `translate(-50%, -50%) scale(${popupScale}) translate(${popupTranslateX}px, ${popupTranslateY}px)`;
}
}
// 开始拖动弹窗图片
function popupStartDrag(e) {
if (e.touches && e.touches.length === 2) {
isPinching = true;
const dx = e.touches[0].clientX - e.touches[1].clientX;
const dy = e.touches[0].clientY - e.touches[1].clientY;
startDistance = Math.sqrt(dx * dx + dy * dy);
startScale = popupScale;
} else {
isPopupDragging = true;
popupStartX = e.clientX || e.touches[0].clientX;
popupStartY = e.clientY || e.touches[0].clientY;
popupStartTranslateX = popupTranslateX;
popupStartTranslateY = popupTranslateY;
}
}
// 拖动或缩放弹窗图片
function popupDrag(e) {
if (isPinching) {
if (e.touches.length === 2) {
const dx = e.touches[0].clientX - e.touches[1].clientX;
const dy = e.touches[0].clientY - e.touches[1].clientY;
const currentDistance = Math.sqrt(dx * dx + dy * dy);
const scaleFactor = currentDistance / startDistance;
popupScale = startScale * scaleFactor;
applyPopupZoom();
}
} else if (isPopupDragging) {
const x = e.clientX || e.touches[0].clientX;
const y = e.clientY || e.touches[0].clientY;
// 根据缩放比例调整拖动灵敏度
const sensitivityFactor = BASE_SENSITIVITY / (1 + SENSITIVITY_ADJUSTMENT * (popupScale - 1));
let newTranslateX = popupStartTranslateX + (x - popupStartX) * sensitivityFactor;
let newTranslateY = popupStartTranslateY + (y - popupStartY) * sensitivityFactor;
// 获取弹窗和图片元素
const popupContent = document.querySelector('.popup-content');
const originalImage1 = document.getElementById('originalImage1');
const popupWidth = popupContent.offsetWidth;
const popupHeight = popupContent.offsetHeight;
const imgWidth = originalImage1.naturalWidth * popupScale;
const imgHeight = originalImage1.naturalHeight * popupScale;
// 更精准的水平方向拖动边界处理
if (imgWidth > popupWidth) {
const maxTranslateX = (imgWidth - popupWidth) / 2;
newTranslateX = Math.min(Math.max(newTranslateX, -maxTranslateX), maxTranslateX);
} else {
newTranslateX = 0;
}
// 更精准的垂直方向拖动边界处理
if (imgHeight > popupHeight) {
const maxTranslateY = (imgHeight - popupHeight) / 2;
newTranslateY = Math.min(Math.max(newTranslateY, -maxTranslateY), maxTranslateY);
} else {
newTranslateY = 0;
}
popupTranslateX = newTranslateX;
popupTranslateY = newTranslateY;
applyPopupZoom();
}
}
// function popupDrag(e) {
// if (isPinching) {
// if (e.touches.length === 2) {
// const dx = e.touches[0].clientX - e.touches[1].clientX;
// const dy = e.touches[0].clientY - e.touches[1].clientY;
// const currentDistance = Math.sqrt(dx * dx + dy * dy);
// const scaleFactor = currentDistance / startDistance;
// popupScale = startScale * scaleFactor;
// applyPopupZoom();
// }
// } else if (isPopupDragging) {
// const x = e.clientX || e.touches[0].clientX;
// const y = e.clientY || e.touches[0].clientY;
// popupTranslateX = popupStartTranslateX + (x - popupStartX);
// popupTranslateY = popupStartTranslateY + (y - popupStartY);
// applyPopupZoom();
// }
// }
// 结束拖动或缩放弹窗图片
function popupEndDrag(e) {
isPopupDragging = false;
isPinching = false;
}
// 处理鼠标滚轮事件
function handleWheel(e) {
e.preventDefault();
const delta = e.deltaY || e.detail || e.wheelDelta;
if (delta < 0) {
// 向上滚动,放大
popupZoomIn();
} else {
// 向下滚动,缩小
popupZoomOut();
}
}
// 为弹窗图片添加事件监听器
const originalImage1 = document.getElementById('originalImage1');
const originalImage2 = document.getElementById('originalImage2');
const compareBtn = document.querySelector('.compare-btn');
originalImage1.addEventListener('mousedown', popupStartDrag);
originalImage1.addEventListener('touchstart', popupStartDrag);
originalImage2.addEventListener('mousedown', popupStartDrag);
originalImage2.addEventListener('touchstart', popupStartDrag);
document.addEventListener('mousemove', popupDrag);
document.addEventListener('touchmove', popupDrag);
document.addEventListener('mouseup', popupEndDrag);
document.addEventListener('touchend', popupEndDrag);
originalImage1.addEventListener('wheel', handleWheel);
originalImage2.addEventListener('wheel', handleWheel);
displayGroup();
</script>
</body>
</html>