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

Scroll only X and Y if viewport is zoomed #62

Closed DavorBeg closed 10 months ago

DavorBeg commented 10 months ago

Hi! Is it possible to move only X position (left and right), but allow to scroll Y if I zoom in viewport. (scroll only viewport height) Thanks!

DavorBeg commented 10 months ago

I found soulution. So rangeY is [0, 0] until I zoom container, then I enable rangeY to scroll height of schedulerHeight. Maybe I didnt explained very well, if somebody will find similar problem I can create GIF to show what I mean.

  const maxZoom = SchedulerInfiniteViewer.zoomRange[1];
  const schedulerHeight = schedulerViewPort.clientHeight;
SchedulerInfiniteViewer.on("scroll", () => {
    const currentZoom = Math.pow(SchedulerInfiniteViewer.getZoom(), 1);
    const zoomPercentage = ((currentZoom - 1) / (maxZoom - 1))

    // finaly set new Y range after zoom
   SchedulerInfiniteViewer.rangeY = [0, ((currentZoom * schedulerHeight) - schedulerHeight) / currentZoom];

});