mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-11-30 02:08:12 +08:00
refactor(components): [image-viewer] optimise translate calc method (#13157)
* Use trigonometric functions to calculate translate, which can support any angle
This commit is contained in:
parent
d94aa4cdb5
commit
94a24dcbc8
@ -178,20 +178,11 @@ const imgStyle = computed(() => {
|
||||
let translateX = offsetX / scale
|
||||
let translateY = offsetY / scale
|
||||
|
||||
switch (deg % 360) {
|
||||
case 90:
|
||||
case -270:
|
||||
;[translateX, translateY] = [translateY, -translateX]
|
||||
break
|
||||
case 180:
|
||||
case -180:
|
||||
;[translateX, translateY] = [-translateX, -translateY]
|
||||
break
|
||||
case 270:
|
||||
case -90:
|
||||
;[translateX, translateY] = [-translateY, translateX]
|
||||
break
|
||||
}
|
||||
const radian = (deg * Math.PI) / 180
|
||||
const cosRadian = Math.cos(radian)
|
||||
const sinRadian = Math.sin(radian)
|
||||
translateX = translateX * cosRadian + translateY * sinRadian
|
||||
translateY = translateY * cosRadian - (offsetX / scale) * sinRadian
|
||||
|
||||
const style: CSSProperties = {
|
||||
transform: `scale(${scale}) rotate(${deg}deg) translate(${translateX}px, ${translateY}px)`,
|
||||
|
Loading…
Reference in New Issue
Block a user