@hoangyell/gallery 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Gallery.astro +44 -3
package/package.json
CHANGED
package/src/Gallery.astro
CHANGED
|
@@ -500,6 +500,12 @@ if (resolvedRows <= 1 || galleryItems.length <= 1) {
|
|
|
500
500
|
currentIndex: number;
|
|
501
501
|
touchStartX: number;
|
|
502
502
|
touchStartY: number;
|
|
503
|
+
lockedScrollY: number;
|
|
504
|
+
previousBodyOverflow: string;
|
|
505
|
+
previousBodyPosition: string;
|
|
506
|
+
previousBodyTop: string;
|
|
507
|
+
previousBodyWidth: string;
|
|
508
|
+
previousHtmlOverflow: string;
|
|
503
509
|
|
|
504
510
|
constructor(el: HTMLElement) {
|
|
505
511
|
this.gallery = el;
|
|
@@ -514,6 +520,12 @@ if (resolvedRows <= 1 || galleryItems.length <= 1) {
|
|
|
514
520
|
this.currentIndex = -1;
|
|
515
521
|
this.touchStartX = 0;
|
|
516
522
|
this.touchStartY = 0;
|
|
523
|
+
this.lockedScrollY = -1;
|
|
524
|
+
this.previousBodyOverflow = "";
|
|
525
|
+
this.previousBodyPosition = "";
|
|
526
|
+
this.previousBodyTop = "";
|
|
527
|
+
this.previousBodyWidth = "";
|
|
528
|
+
this.previousHtmlOverflow = "";
|
|
517
529
|
|
|
518
530
|
this.bind();
|
|
519
531
|
document.addEventListener("astro:before-swap", this.forceClose);
|
|
@@ -539,10 +551,10 @@ if (resolvedRows <= 1 || galleryItems.length <= 1) {
|
|
|
539
551
|
|
|
540
552
|
document.removeEventListener("keydown", this.handleKey);
|
|
541
553
|
document.removeEventListener("gesturestart", this.preventZoom);
|
|
542
|
-
document.body.style.overflow = "";
|
|
543
554
|
const main = document.querySelector("main");
|
|
544
555
|
if (main) main.removeAttribute("inert");
|
|
545
556
|
}
|
|
557
|
+
this.unlockBackgroundScroll();
|
|
546
558
|
document.removeEventListener("astro:before-swap", this.forceClose);
|
|
547
559
|
};
|
|
548
560
|
|
|
@@ -561,7 +573,7 @@ if (resolvedRows <= 1 || galleryItems.length <= 1) {
|
|
|
561
573
|
this.preload(index + 1);
|
|
562
574
|
|
|
563
575
|
document.body.appendChild(this.overlay);
|
|
564
|
-
|
|
576
|
+
this.lockBackgroundScroll();
|
|
565
577
|
const main = document.querySelector("main");
|
|
566
578
|
if (main) main.setAttribute("inert", "");
|
|
567
579
|
this.overlay.focus();
|
|
@@ -650,7 +662,7 @@ if (resolvedRows <= 1 || galleryItems.length <= 1) {
|
|
|
650
662
|
this.imgEl = null;
|
|
651
663
|
this.counterEl = null;
|
|
652
664
|
|
|
653
|
-
|
|
665
|
+
this.unlockBackgroundScroll();
|
|
654
666
|
const main = document.querySelector("main");
|
|
655
667
|
if (main) main.removeAttribute("inert");
|
|
656
668
|
|
|
@@ -663,6 +675,35 @@ if (resolvedRows <= 1 || galleryItems.length <= 1) {
|
|
|
663
675
|
}, 300);
|
|
664
676
|
};
|
|
665
677
|
|
|
678
|
+
lockBackgroundScroll = () => {
|
|
679
|
+
if (this.lockedScrollY >= 0) return;
|
|
680
|
+
|
|
681
|
+
this.lockedScrollY = window.scrollY;
|
|
682
|
+
this.previousBodyOverflow = document.body.style.overflow;
|
|
683
|
+
this.previousBodyPosition = document.body.style.position;
|
|
684
|
+
this.previousBodyTop = document.body.style.top;
|
|
685
|
+
this.previousBodyWidth = document.body.style.width;
|
|
686
|
+
this.previousHtmlOverflow = document.documentElement.style.overflow;
|
|
687
|
+
|
|
688
|
+
document.documentElement.style.overflow = "hidden";
|
|
689
|
+
document.body.style.overflow = "hidden";
|
|
690
|
+
document.body.style.position = "fixed";
|
|
691
|
+
document.body.style.top = `-${this.lockedScrollY}px`;
|
|
692
|
+
document.body.style.width = "100%";
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
unlockBackgroundScroll = () => {
|
|
696
|
+
if (this.lockedScrollY < 0) return;
|
|
697
|
+
|
|
698
|
+
document.documentElement.style.overflow = this.previousHtmlOverflow;
|
|
699
|
+
document.body.style.overflow = this.previousBodyOverflow;
|
|
700
|
+
document.body.style.position = this.previousBodyPosition;
|
|
701
|
+
document.body.style.top = this.previousBodyTop;
|
|
702
|
+
document.body.style.width = this.previousBodyWidth;
|
|
703
|
+
window.scrollTo(0, this.lockedScrollY);
|
|
704
|
+
this.lockedScrollY = -1;
|
|
705
|
+
};
|
|
706
|
+
|
|
666
707
|
navigate = (dir: number) => {
|
|
667
708
|
const next = this.currentIndex + dir;
|
|
668
709
|
if (next < 0 || next >= this.items.length) return;
|