Skip to content

Commit 49c5b16

Browse files
committed
[TASK] Separate the reset of the image zoom into its own function
1 parent 4e472ef commit 49c5b16

File tree

5 files changed

+83
-44
lines changed

5 files changed

+83
-44
lines changed

dist/js/parvus.esm.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,11 @@ function Parvus(userOptions) {
539539
}
540540
lightbox.classList.add('parvus--is-closing');
541541
const transitionendHandler = () => {
542+
// Reset the image zoom (if ESC was pressed or went back in the browser history)
543+
// after the ViewTransition (otherwise it looks bad)
544+
if (isPinching) {
545+
resetZoom(IMAGE);
546+
}
542547
leaveSlide(currentIndex);
543548
lightbox.close();
544549
lightbox.classList.remove('parvus--is-closing');
@@ -1036,6 +1041,25 @@ function Parvus(userOptions) {
10361041
contentEl.style.height = USE_ORIGINAL_SIZE ? '' : `${NEW_HEIGHT}px`;
10371042
};
10381043

1044+
/**
1045+
* Reset image zoom
1046+
*
1047+
* @param {HTMLImageElement} currentImg - The image
1048+
*/
1049+
const resetZoom = currentImg => {
1050+
currentImg.style.transition = 'transform 0.3s ease';
1051+
currentImg.style.transform = '';
1052+
setTimeout(() => {
1053+
currentImg.style.transition = '';
1054+
currentImg.style.transformOrigin = '';
1055+
}, 300);
1056+
isPinching = false;
1057+
currentScale = 1;
1058+
pinchStartDistance = 0;
1059+
lastPointersId = '';
1060+
lightbox.classList.remove('parvus--is-zooming');
1061+
};
1062+
10391063
/**
10401064
* Pinch zoom gesture
10411065
*
@@ -1258,17 +1282,7 @@ function Parvus(userOptions) {
12581282
}
12591283
} else {
12601284
if (isPinching) {
1261-
CURRENT_IMAGE.style.transition = 'transform 0.3s ease';
1262-
CURRENT_IMAGE.style.transform = '';
1263-
setTimeout(() => {
1264-
CURRENT_IMAGE.style.transition = '';
1265-
CURRENT_IMAGE.style.transformOrigin = '';
1266-
}, 300);
1267-
isPinching = false;
1268-
currentScale = 1;
1269-
pinchStartDistance = 0;
1270-
lastPointersId = '';
1271-
lightbox.classList.remove('parvus--is-zooming');
1285+
resetZoom(CURRENT_IMAGE);
12721286
}
12731287
if (drag.endX || drag.endY) {
12741288
updateAfterDrag();

0 commit comments

Comments
 (0)