anvaka / panzoom

Universal pan and zoom library (DOM, SVG, Custom)

Home Page:https://anvaka.github.io/panzoom/demo/attach-via-script.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I center the screen and display it to fit the current screen size?

danhk0612 opened this issue · comments

I use code below.

const screenSize = {
 "w": Math.max(document.documentElement.clientWidth, window.innerWidth || 0),
 "h": Math.max(document.documentElement.clientHeight, window.innerHeight || 0)
};
let initalZoom = (screenSize.w / elemWid < screenSize.h / elemHei) ? screenSize.w / elemWid  : screenSize.h / elemHei;
panzoomObj.zoomAbs(0, 0, initalZoom);
panzoomObj.moveTo((screenSize.w - elemWid * initalZoom) / 2, (screenSize.h - elemHei * initalZoom) / 2);

It works well.
but I want to know Is there a way to make this code more efficient, or is there an internal method?

I found this:

autocenter?: boolean;
but it does not work as well as your snippet.