feat: keep aspect ratio when drag image #414
This commit is contained in:
@@ -179,15 +179,31 @@ export class Previewer {
|
||||
let dy = 0
|
||||
switch (this.curHandleIndex) {
|
||||
case 0:
|
||||
dx = this.mousedownX - evt.x
|
||||
dy = this.mousedownY - evt.y
|
||||
{
|
||||
const offsetX = this.mousedownX - evt.x
|
||||
const offsetY = this.mousedownY - evt.y
|
||||
dx = Math.cbrt(offsetX ** 3 + offsetY ** 3)
|
||||
dy = (this.curElement.height! * dx) / this.curElement.width!
|
||||
}
|
||||
break
|
||||
case 1:
|
||||
dy = this.mousedownY - evt.y
|
||||
break
|
||||
case 2:
|
||||
dx = evt.x - this.mousedownX
|
||||
dy = this.mousedownY - evt.y
|
||||
{
|
||||
const offsetX = evt.x - this.mousedownX
|
||||
const offsetY = this.mousedownY - evt.y
|
||||
dx = Math.cbrt(offsetX ** 3 + offsetY ** 3)
|
||||
dy = (this.curElement.height! * dx) / this.curElement.width!
|
||||
}
|
||||
break
|
||||
case 4:
|
||||
{
|
||||
const offsetX = evt.x - this.mousedownX
|
||||
const offsetY = evt.y - this.mousedownY
|
||||
dx = Math.cbrt(offsetX ** 3 + offsetY ** 3)
|
||||
dy = (this.curElement.height! * dx) / this.curElement.width!
|
||||
}
|
||||
break
|
||||
case 3:
|
||||
dx = evt.x - this.mousedownX
|
||||
@@ -196,16 +212,16 @@ export class Previewer {
|
||||
dy = evt.y - this.mousedownY
|
||||
break
|
||||
case 6:
|
||||
dx = this.mousedownX - evt.x
|
||||
dy = evt.y - this.mousedownY
|
||||
{
|
||||
const offsetX = this.mousedownX - evt.x
|
||||
const offsetY = evt.y - this.mousedownY
|
||||
dx = Math.cbrt(offsetX ** 3 + offsetY ** 3)
|
||||
dy = (this.curElement.height! * dx) / this.curElement.width!
|
||||
}
|
||||
break
|
||||
case 7:
|
||||
dx = this.mousedownX - evt.x
|
||||
break
|
||||
default:
|
||||
dx = evt.x - this.mousedownX
|
||||
dy = evt.y - this.mousedownY
|
||||
break
|
||||
}
|
||||
// 图片实际宽高(变化大小除掉缩放比例)
|
||||
const dw = this.curElement.width! + dx / scale
|
||||
|
||||
Reference in New Issue
Block a user