daybrush / infinite-viewer

Infinite Viewer is Document Viewer Component with infinite scrolling.
https://daybrush.com/infinite-viewer/
MIT License
283 stars 30 forks source link

Wrong position when zoom value different from 100% #41

Closed leidto closed 1 year ago

leidto commented 1 year ago

I'm working on a canvas-like editor. I want to load the position with zoom level what the user previously saved. Loading the position works perfectly with 100% zoom level. When the zoom level is different than 100% it miscalculates.

What do you recommend to solve this?

const save = () => {
      const left = viewerRef.current.getScrollLeft()
      const top = viewerRef.current.getScrollTop()
      const zoom = viewerRef.current.getZoom()
}

const load = () => {
      viewerRef.current.scrollTo(layout.left, layout.top)
      // Works correctly if zoom = 1
      viewerRef.current.setZoom(layout.zoom)
}

<InfiniteViewer
        ref={viewerRef}
        useMouseDrag
        onScroll={handleOnScroll}
        ...
>
daybrush commented 1 year ago

@leidto

I'll fix it soon. and release it this week.

daybrush commented 1 year ago

@leidto

infinite-viewer's new version is released.

By default, setZoom zooms by 50% and 50% based on the screen.

use with zoomOffsetX, zoomOffsetY

viewer.setZoom(zoom,  {
   zoomOffsetX: 0,
   zoomOffsetY: 0,
});
leidto commented 1 year ago

Perfect! 👍🏻