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