diff --git a/src/plugins/zoom/lg-zoom-settings.ts b/src/plugins/zoom/lg-zoom-settings.ts index 54643fb49..3b90001fd 100644 --- a/src/plugins/zoom/lg-zoom-settings.ts +++ b/src/plugins/zoom/lg-zoom-settings.ts @@ -20,6 +20,11 @@ export interface ZoomSettings { */ zoom: boolean; + /** + * Enable/Disable mousewheel option + */ + wheelZoom: boolean; + /** * Enable/Disable infinite zoom * @description If you set this to true, you can zoom in more than the original size of the image. @@ -61,6 +66,7 @@ export interface ZoomSettings { export const zoomSettings: ZoomSettings = { scale: 1, zoom: true, + wheelZoom: false, infiniteZoom: true, actualSize: true, showZoomInOutIcons: false, diff --git a/src/plugins/zoom/lg-zoom.ts b/src/plugins/zoom/lg-zoom.ts index 7f07dd78c..f6eb1b13c 100644 --- a/src/plugins/zoom/lg-zoom.ts +++ b/src/plugins/zoom/lg-zoom.ts @@ -123,6 +123,16 @@ export default class Zoom { ); } + enableWheelZoom(): void { + if (!this.settings.wheelZoom) { + return; + } + this.core.outer.on('wheel.lg', (event: WheelEvent) => { + event.preventDefault(); + event.deltaY > 0 ? this.zoomOut() : this.zoomIn(); + }); + } + getDragCords(e: MouseEvent): Coords { return { x: e.pageX, @@ -573,30 +583,7 @@ export default class Zoom { }); this.core.getElementById('lg-zoom-out').on('click.lg', () => { - // Allow zoom only on image - if (!this.isImageSlide(this.core.index)) { - return; - } - - let timeout = 0; - if (this.imageReset) { - this.resetImageTranslate(this.core.index); - timeout = 50; - } - setTimeout(() => { - let scale = this.scale - this.settings.scale; - - if (scale < 1) { - scale = 1; - } - this.beginZoom(scale); - this.zoomImage( - scale, - -this.settings.scale, - true, - !this.settings.infiniteZoom, - ); - }, timeout); + this.zoomOut(); }); this.core.getElementById('lg-zoom-in').on('click.lg', () => { @@ -643,6 +630,8 @@ export default class Zoom { this.zoomSwipe(); + this.enableWheelZoom(); + // Store the zoomable timeout value just to clear it while closing this.zoomableTimeout = false; this.positionChanged = false; @@ -669,6 +658,33 @@ export default class Zoom { ); } + zoomOut(): void { + // Allow zoom only on image + if (!this.isImageSlide(this.core.index)) { + return; + } + + let timeout = 0; + if (this.imageReset) { + this.resetImageTranslate(this.core.index); + timeout = 50; + } + setTimeout(() => { + let scale = this.scale - this.settings.scale; + + if (scale < 1) { + scale = 1; + } + this.beginZoom(scale); + this.zoomImage( + scale, + -this.settings.scale, + true, + !this.settings.infiniteZoom, + ); + }, timeout); + } + // Reset zoom effect resetZoom(index?: number): void { this.core.outer.removeClass('lg-zoomed lg-zoom-drag-transition');