【发布时间】:2022-01-23 21:59:22
【问题描述】:
我正在尝试调整 div 的角度以保持(矩形的)纵横比。但我做不到。我无法拖动 div 的角并调整其大小。这是一个stackbliz
https://stackblitz.com/edit/icon-font-awesome-f6ydhr?file=src/app/app.component.ts
我尝试使用这个答案: https://stackoverflow.com/a/30494623/1540456
但没有成功。 这是一些代码
import { Component } from "@angular/core";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
width= 300;
height= 150;
color= 'red';
dragEvent(event: MouseEvent) {
let ratio = (16 / 10);
let diagonal = this.height * ratio;
this.height = this.getHeight(diagonal, ratio);
this.width = this.getWidth(this.height, ratio);
}
getHeight(length, ratio) {
let height = ((length) / (Math.sqrt((Math.pow(ratio, 2) + 1))));
return Math.round(height);
}
getWidth(length, ratio) {
let width = ((length) / (Math.sqrt((1) / (Math.pow(ratio, 2) + 1))));
return Math.round(width);
}
}
在html中
<div class="resize" (mousedown)="dragEvent($event)">
<p>drag</p>
</div>
【问题讨论】:
标签: angular typescript resize drag proportions