缩放到中心

时间:2019-01-29 22:16:51

标签: javascript

我试图在缩放的中心设置在视口的中间进行缩放。现在,缩放点位于左上角,我想将缩放点移到视口的中间。这是我的逻辑

zoomIn() {
const scrollHeight = this.scroll._scrollContent.nativeElement.scrollHeight;
const scrollWidth = this.scroll._scrollContent.nativeElement.scrollWidth;
const offsetWidth = this.scroll._scrollContent.nativeElement.scrollLeft;
const offsetHeight = this.scroll._scrollContent.nativeElement.scrollTop;

const widthRatio = offsetWidth/scrollWidth;
const heightRatio = offsetHeight/scrollHeight;
console.log({scrollHeight, scrollWidth, offsetHeight, offsetWidth, heightRatio, widthRatio});

this.scale = Zoom.calculateZoom(this.scale, ZoomDirection.UP);
this.painter.zoom(this.scale);

const scrollHeightAfterZoom = this.scroll._scrollContent.nativeElement.scrollHeight;
const scrollWidthAfterZoom = this.scroll._scrollContent.nativeElement.scrollWidth;


const moveScrollHeight = scrollHeightAfterZoom*heightRatio;
const moveScrollWidth = scrollWidthAfterZoom*widthRatio;
this.scroll._scrollContent.nativeElement.scrollTo({ left: moveScrollWidth, top: moveScrollHeight })
  }

我可能应该考虑视口的大小和比例,但无法正确处理。

0 个答案:

没有答案