首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Angular 5中使用图像缩放功能

如何在Angular 5中使用图像缩放功能
EN

Stack Overflow用户
提问于 2018-08-23 16:50:28
回答 3查看 13.5K关注 0票数 0

我正在用Angular 5开发一个web应用程序,我想使用图像缩放功能,如下面的链接所述

https://www.w3schools.com/howto/howto_js_image_zoom.asp

该链接很好地解释了一些图像缩放功能,但它使用了标签中定义的java脚本。

我的问题是如何在Angular 5或Angular 6中使用这些特性

谢谢Sachin

EN

回答 3

Stack Overflow用户

发布于 2018-08-23 17:21:47

尝试如下所示:

DEMO

HTML:

代码语言:javascript
复制
<h1>Image Zoom</h1>

<p>Mouse over the image:</p>

<div class="img-zoom-container" (mouseenter)="imageZoom('myimage', 'myresult');">
    <img id="myimage" src="https://user-images.githubusercontent.com/263237/36633897-d3237f2e-19ad-11e8-960a-daaf5ca3088a.png"
     width="300" height="240">
    <div id="myresult" class="img-zoom-result"></div>
</div>

CSS:

代码语言:javascript
复制
* {box-sizing: border-box;}

.img-zoom-container {
  position: relative;
} 

.img-zoom-lens {
  position: absolute;
  border: 1px solid #d4d4d4;
  /*set the size of the lens:*/
  width: 40px;
  height: 40px;
}

.img-zoom-result {
  border: 1px solid #d4d4d4;
  /*set the size of the result div:*/
  width: 300px;
  height: 300px;
}
票数 7
EN

Stack Overflow用户

发布于 2021-08-05 05:09:38

使用这个ng-img-magnifier npm包。点击DEMO查看这个Angular Image Zoom包的工作示例。它很容易实现,并提供完全定制。

代码语言:javascript
复制
<ng-img-magnifier [thumbImage]='img' [fullImage]='img2'
    [imgWidth]='imgWidth' [imgHeight]='imgheight'
    [top]='top' [right]='right'
    [lensWidth]='lensewidth' [lensHeight]='lensheight'
    [resultWidth]='resultWidth' [resultHeight]='resultheight'>
</ng-img-magnifier>
票数 0
EN

Stack Overflow用户

发布于 2021-08-05 06:44:26

使用ngx-image-zoom库进行图像缩放,因此可以这样安装它:

代码语言:javascript
复制
$ npm install ngx-image-zoom --save

安装完成后,像这样装饰你的Angular应用模板、组件和模块:

app.component.html:

代码语言:javascript
复制
<lib-ngx-image-zoom
    [thumbImage]=myThumbnail
    [fullImage]=myFullresImage>
</lib-ngx-image-zoom>

app.component.ts:

代码语言:javascript
复制
import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  myThumbnail="Thumb image path goes here";
  myFullresImage="Fullers image path goes here";
}

app.module.ts:

代码语言:javascript
复制
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 { }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51981790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档