Merge pull request #6170 from Rob--W/zoom-at-cursor
Zoom relative to cursor position via mouse wheel
This commit is contained in:
commit
3ffed9d083
@ -1811,14 +1811,31 @@ function handleMouseWheel(evt) {
|
|||||||
evt.wheelDelta / MOUSE_WHEEL_DELTA_FACTOR;
|
evt.wheelDelta / MOUSE_WHEEL_DELTA_FACTOR;
|
||||||
var direction = (ticks < 0) ? 'zoomOut' : 'zoomIn';
|
var direction = (ticks < 0) ? 'zoomOut' : 'zoomIn';
|
||||||
|
|
||||||
if (PDFViewerApplication.pdfViewer.isInPresentationMode) {
|
var pdfViewer = PDFViewerApplication.pdfViewer;
|
||||||
|
if (pdfViewer.isInPresentationMode) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
PDFViewerApplication.scrollPresentationMode(ticks *
|
PDFViewerApplication.scrollPresentationMode(ticks *
|
||||||
MOUSE_WHEEL_DELTA_FACTOR);
|
MOUSE_WHEEL_DELTA_FACTOR);
|
||||||
} else if (evt.ctrlKey || evt.metaKey) {
|
} else if (evt.ctrlKey || evt.metaKey) {
|
||||||
// Only zoom the pages, not the entire viewer.
|
// Only zoom the pages, not the entire viewer.
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
|
var previousScale = pdfViewer.currentScale;
|
||||||
|
|
||||||
PDFViewerApplication[direction](Math.abs(ticks));
|
PDFViewerApplication[direction](Math.abs(ticks));
|
||||||
|
|
||||||
|
var currentScale = pdfViewer.currentScale;
|
||||||
|
if (previousScale !== currentScale) {
|
||||||
|
// After scaling the page via zoomIn/zoomOut, the position of the upper-
|
||||||
|
// left corner is restored. When the mouse wheel is used, the position
|
||||||
|
// under the cursor should be restored instead.
|
||||||
|
var scaleCorrectionFactor = currentScale / previousScale - 1;
|
||||||
|
var rect = pdfViewer.container.getBoundingClientRect();
|
||||||
|
var dx = evt.clientX - rect.left;
|
||||||
|
var dy = evt.clientY - rect.top;
|
||||||
|
pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
|
||||||
|
pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user