view-bigimg icon indicating copy to clipboard operation
view-bigimg copied to clipboard

event.pageX bug with scrollbar

Open TomWyllie opened this issue 3 years ago • 0 comments

When using an image that is embedded far enough down a page that a scrollbar is required, the zoom functionality has a bug. When zooming in and out, the location of the mouse is erroneously offset by the current position of the scrollbars, so the image doesn't zoom in to where the cursor was actually pointing. This is because touch events use pageX and pageY which is relative to the origin of the document, which may be scrolled out of view.

This bug can be fixed by using clientX and clientY, which is relative to the viewport, and gives correct coordinates no matter what the position of the document is in the viewport. So the following substitutions should occur for all of the following (I have done this locally):

event.pageX -> event.clientX event.pageY -> event.clientY

Thanks for a nice library :)

TomWyllie avatar Jan 16 '22 20:01 TomWyllie