[](https://npmjs.org/package/ngx-image-zoom)
npm install maple-zoom
This version is only tested with Angular13. Moving forward this library may or may not work on older versions
of Angular anymore.
Still in early development, more features are planned and incoming. Should be in a working
state right now but it's not tested in lots of different setups yet.
Breaking changes in version 0.5.0, see changelog for details.
Demonstration of available features available here.
NgxImageZoom is inspired by angular2-image-zoom and
JQuery libraries such as jQuery Zoom and
elevateZoom-plus but a pure Angular2+ implementation of
similar concepts. This plugin works with both URLs to images and in-line images
(Data URI).
All settings except thumbImage are optional. If no fullImage is provided the thumbImage will be
used as the high resolution version as well.
Option | Default value | Description
:---:|:---:|---
thumbImage | none | (Required) The smaller version of the image that will be shown when there's no interaction by the user.
fullImage | none | The full resolution version of the image to be used when zooming. If not supplied thumbImage will be used.
magnification | 1 | The zoom factor to be used by default. 1 means we use the fullImage at its actual resolution.
zoomMode | 'hover' | The mode of zooming to use, these are explained in a table below.
enableScrollZoom | false | Boolean that toggles if the mouse wheel should be captured when hovering over the image to adjust magnification.
scrollStepSize | 0.1 | When using scroll zoom this setting determines how big steps each scroll changes the zoom.
enableLens | false | If enabled only a small portion around the mouse cursor will actually magnify instead of the entire image area.
lensWidth | 100 | Width of the lens, if enabled.
lensHeight | 100 | Height of the lens, if enabled.
circularLens | false | Make the lens circular instead of square. This will only look good if width and height are equal.
minZoomRatio | baseRatio | Lower limit on how much zoom can be applied with scrollZoom enabled. See below for details.
maxZoomRatio | 2 | Upper limit on how much zoom can be applied with scrollZoom enabled. See below for details.
altText | '' | alt attribute of the thumb and full image.
titleText | '' | title attribute of the thumb and full image.
The component outputs the follow events that can be triggered on.
Event name | Description
:---:|---
zoomScroll | Whenever the user changes the zoom level using the scroll wheel this event will fire with the current zoom ratio (see above).
zoomPosition | When the point on where the zoom is focused changes this event emits a Coord event (interface exported from the module) with X/Y in pixels relative thumbnails top left corner. Practically whenever the user moves the mouse cursor over the image.
imagesLoaded | When the thumbnail and fullImage are loaded and ready to be used this output emits "true". It will emit "false" if images are changed and on initial setup
To install this library, run:
``bash`
$ npm install ngx-image-zoom --save
From your Angular AppModule:
`typescript
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
// Import the library
import { NgxImageZoomModule } from 'ngx-image-zoom';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
NgxImageZoomModule // <-- Add this line
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
`
Once the library is imported, you can use its component in your Angular application:
`xml``
{{title}}
[fullImage]=myFullresImage
>
MIT © Mathias Wittlock