我正在尝试从ngx图像裁剪放大和缩小。我没有得到任何错误,但当我点击按钮zoomOut或ZoomIn它不工作。
我在这里做错了什么?
我的TS代码
zoomOut() {
this.scale -= .1;
this.transform = {
...this.transform,
scale: this.scale
};
}
zoomIn() {
this.scale += .1;
this.transform = {
...this.transform,
scale: this.scale
};
}我的HTML代码
<button class="btn zoomIn" (click)="zoomIn()" tooltip="Zoom In" data-toggle="tooltip" data-placement="top" title="Zoom In"></button>
<button class="btn zoomOut" (click)="zoomOut()" tooltip="Zoom Out" data-toggle="tooltip" data-placement="top" title="Zoom Out"></button>发布于 2021-02-03 18:19:15
它类似于这个another SO。实际上角度总是一样的,把.ts (模型)和.html (视图)中的变量联系起来。嗯,在文档中,about binding是非常差的。就我个人而言,我讨厌示例{{variable}} :)
您可以声明一个变量scale
scale:number=1;
<!--see that you can use the .html to makes "simple code"
(equal a variable to another an so on)
-->
<button class="btn zoomIn" (click)="scale=scale+.1"></button>
<button class="btn zoomIn" (click)="scale=scale-.1"></button>
<img [style.transform]="'scale('+scale+')'" ...>发布于 2021-02-03 22:28:09
export class AppComponent {
zoom:boolean=false;
zoomOut(){
this.zoom=false;
}
zoomIn(){
this.zoom=true;
}
getheight(){
if(this.zoom==true){
return '500px';
//return your desiderd value in pixel or in percentage
}
else{
return '200px';
}
}
}button{
padding: 8px;
}
#test-zoom{
height: 500px;
width: 100%;
position: relative;
background: red;
}
.zoom-card{
height: 500px;
width: 90%;
position: relative;
margin: auto;
background: lime;
}
.test-image{
width: auto;
}<section id="test-zoom">
<div class="zoom-card">
<img [ngStyle]="{'height':getheight()}" width="auto" class="test-image" src="https://www.netcetra.com/images/howto_images/photoshop-logo.jpg">
<br>
<button (click)="zoomIn()" >Zoom In</button>
<button (click)="zoomOut()" >Zoom Out</button>
</div>
</section>
使用此代码并将其粘贴到app.component.ts、CSS和HTML文件中。
https://stackoverflow.com/questions/65998334
复制相似问题