Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Right Aligning On Zoom - No Horizontal Scrollbar to Horizontal Scrollbar state #405

Open
Jacob-Kizzee opened this issue Jun 15, 2018 · 4 comments

Comments

@Jacob-Kizzee
Copy link

Jacob-Kizzee commented Jun 15, 2018

Hello,

I have run across an issue while implementing Diva for a client. As seen in GIF below the renderer right aligns the page when zooming from a "no-horizontal-scrollbar" state to a "horizontal-scrollbar" state.

I have used the basic demo to illustrate the issue.

diva js-try

The expected result on zoom would be to zoom to center. The zoom-in function works properly and zooms on the center of the view window if the "horizontal-scrollbar" already exists.

The issue appears to lie in the handleZoom function of viewer-core.js. When a focalpoint is not provided (zoom button clicked, not a double click) we see:
offset.left = (viewport.width / 2) - (currentRegion.left - viewport.left)

After reviewing the values of viewport and currentRegion I was unable to understand when and where these values are calculated during the zoom process. They appear to jump around severely when moving between "no-horizontal-scrollbar" state to a "horizontal-scrollbar" state.

The revised code below produces a centered view on zoom into a horizontal scrollbar state, but harms the math for the next zoom-in level when the scrollbar exists:
offset.left = (viewport.width > (viewport._innerDimensions.width / 2) ? (viewport._innerDimensions.width / 2) : viewport.width)/2 - (currentRegion.left - viewport.left)

Am I missing a setting for center align on zoom or has anyone else seen this issue?

Your help and consideration are both greatly appreciated.

Thanks

@EricHanLiu
Copy link
Contributor

EricHanLiu commented Jun 20, 2018

This issue also exists when double click zooming (so a focalPoint is given, anywhere on the page) from specific zoom levels and page views. Therefore, it seems like the issue shouldn't even be within the focalPoint calculation (where

left: (viewport.width / 2) - (currentRegion.left - viewport.left)

is calculated) since this calculation shouldn't even happen when double click zooming

Using the basic demo:

  • In single page view, going from zoomLevel 2.0 and 3.0 will right align the page, whether using the zoom buttons or double click zooming (anywhere on the page)
  • In book page view, going from zoomLevel 1.0 and 2.0 will right align the page, using either zoom method as well.

It is likely that these exact zoomLevels are only compatible with my exact viewport size.
eg. the horizontal scrollbar only appears at zoomlevel 3.0 in single page , but could be at 2.0 for another monitor

@EricHanLiu
Copy link
Contributor

EricHanLiu commented Jun 20, 2018

The issue seems to be inside the getPositionForZoomLevel(zoomLevel) function (within handleZoom), when calculating the horizontalOffset.

The exact calculation is

var horizontalOffset = (focalPoint.offset.left * zoomRatio) - focalXToCenter;

It seems the issue could lie with the focalXToCenter, or the focalPoint.offset.left variables

Changing this value changes the alignment when zooming between a no-scrollbar to a scrollbar state.

@EricHanLiu
Copy link
Contributor

EricHanLiu commented Jun 20, 2018

Overall it seems that once the zoom level crosses the horizontal scrollbar threshold, the image gets scrolled some pixels to the right (~200px), regardless of where the mouse is. If using double click zooming, it'll still nearly centre around the mouse, but it will offset to the right just a tad

@Jacob-Kizzee
Copy link
Author

Hello,

Has there been any consideration or movement on this item as part of Release 6.0?

Thanks,
Jacob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants