Skip to content

Commit 85ec3a9

Browse files
committed
fix(zoom): zoom button is disabled when clicking too fast
ref #1403
1 parent b6dc65d commit 85ec3a9

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

src/plugins/zoom/lg-zoom.ts

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ interface PossibleCords {
2323
maxX: number;
2424
maxY: number;
2525
}
26+
27+
const ZOOM_TRANSITION_DURATION = 500;
28+
2629
export default class Zoom {
2730
private core: LightGallery;
2831
private settings: ZoomSettings;
@@ -279,11 +282,7 @@ export default class Zoom {
279282
this.top = y;
280283

281284
if (resetToMax) {
282-
const actualSizeScale = this.getCurrentImageActualSizeScale();
283-
284-
if (scale >= actualSizeScale) {
285-
this.setZoomImageSize();
286-
}
285+
this.setZoomImageSize();
287286
}
288287
}
289288

@@ -310,30 +309,47 @@ export default class Zoom {
310309
.first();
311310

312311
setTimeout(() => {
313-
$image.addClass('no-transition');
314-
this.imageReset = true;
315-
}, 500);
312+
const actualSizeScale = this.getCurrentImageActualSizeScale();
313+
314+
if (this.scale >= actualSizeScale) {
315+
$image.addClass('no-transition');
316+
this.imageReset = true;
317+
}
318+
}, ZOOM_TRANSITION_DURATION);
319+
316320
setTimeout(() => {
317-
const dragAllowedAxises = this.getDragAllowedAxises(this.scale);
318-
319-
$image
320-
.css(
321-
'width',
322-
($image.get() as HTMLImageElement).naturalWidth + 'px',
323-
)
324-
.css(
325-
'height',
326-
($image.get() as HTMLImageElement).naturalHeight + 'px',
327-
);
328-
this.core.outer.addClass('lg-actual-size');
329-
if (dragAllowedAxises.allowX && dragAllowedAxises.allowY) {
330-
$image.addClass('reset-transition');
331-
} else if (dragAllowedAxises.allowX && !dragAllowedAxises.allowY) {
332-
$image.addClass('reset-transition-x');
333-
} else if (!dragAllowedAxises.allowX && dragAllowedAxises.allowY) {
334-
$image.addClass('reset-transition-y');
321+
const actualSizeScale = this.getCurrentImageActualSizeScale();
322+
323+
if (this.scale >= actualSizeScale) {
324+
const dragAllowedAxises = this.getDragAllowedAxises(this.scale);
325+
326+
$image
327+
.css(
328+
'width',
329+
($image.get() as HTMLImageElement).naturalWidth + 'px',
330+
)
331+
.css(
332+
'height',
333+
($image.get() as HTMLImageElement).naturalHeight + 'px',
334+
);
335+
336+
this.core.outer.addClass('lg-actual-size');
337+
338+
if (dragAllowedAxises.allowX && dragAllowedAxises.allowY) {
339+
$image.addClass('reset-transition');
340+
} else if (
341+
dragAllowedAxises.allowX &&
342+
!dragAllowedAxises.allowY
343+
) {
344+
$image.addClass('reset-transition-x');
345+
} else if (
346+
!dragAllowedAxises.allowX &&
347+
dragAllowedAxises.allowY
348+
) {
349+
$image.addClass('reset-transition-y');
350+
}
335351
}
336-
}, 550);
352+
}, ZOOM_TRANSITION_DURATION + 50);
337353
}
338354

339355
/**

0 commit comments

Comments
 (0)