简体   繁体   中英

Pan and Zoom Image Plugin

I am trying to implement something like google arts and culture image zoom and pan.

Look here for example.

I tried working with ng2-image-viewer library but can't seem to be able to work it out.

Following is the snippet i tried.

<app-image-viewer 
[images]="['https://images.nga.gov/en/web_images/niagara2.jpg']"
[loadOnInit]="true"
[idContainer]="'idOnHTML'">
</app-image-viewer>

Result:

在此处输入图像描述

As you can see, image is above the expected area, not proper controls and neither is that small rectangle that gives us the minimap.

Follow this:

1- To install this library, run:

npm install iv-viewer
npm install ng2-image-viewer

2- in AppModule

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

// Import your library
import { ImageViewerModule } from 'ng2-image-viewer';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,

    // Specify your library as an import
    ImageViewerModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

3- Now just add the these codes on your angular-cli.json file:

"styles": [
    "../node_modules/ng2-image-viewer/imageviewer.scss"
],

4- Once your library is imported, you can use its components, directives and pipes in your Angular application:

<!-- You can now use your library component in app.component.html -->
<h1>
  Image Viewer
</h1>
<app-image-viewer [images]="['https://picsum.photos/900/500/?random', 'https://picsum.photos/900/500/?random', 'https://picsum.photos/900/500/?random']"
[idContainer]="'idOnHTML'"
[loadOnInit]="true"></app-image-viewer>

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM