Mouse scroll acts as zoom in/out

33 views
Skip to first unread message

Jonathan Readman

unread,
Jan 11, 2018, 12:46:43 PM1/11/18
to PDFTron WebViewer
Hi

Is it possible to change the behaviour of the mouse wheel action when viewing a document? I have a custom button on the page that switches the tool mode to pan as below:

readerControl.setToolMode('Pan');

When it is in this mode I'd like to force the mouse wheel to act as zoom in/out. Is this possible with the webviewer?

Thanks in advance,
Jonathan

Matt Parizeau

unread,
Jan 12, 2018, 3:41:51 PM1/12/18
to PDFTron WebViewer
Hi Jonathan,

By default if you hold the control or alt key down while scrolling the mouse wheel then the page will zoom in/out. This code is found in ReaderControl.js in the constructor and you could tweak it based on your logic. For example, instead of if the ctrlKey is down you check if you're in the alternative mode.

The relevant code looks like:
$viewerElement.bind('mousewheel', function(event, delta) {
 
if (event.ctrlKey || event.altKey) {
   
var sidePanelWidth = me.sidePanelVisible() ? $('#sidePanel').width() : 0;
   
// zoom in and out with ctrl + scrollwheel
   
if (delta < 0) {
      me
.docViewer.zoomToMouse(calcZoomLevelWithBounds(me.getZoomLevel() * 0.8), sidePanelWidth, toolbarOffset);
   
} else {
      me
.docViewer.zoomToMouse(calcZoomLevelWithBounds(me.getZoomLevel() * 1.25), sidePanelWidth, toolbarOffset);
   
}
   
event.preventDefault();
   
return;
 
}
 
...
}

Matt Parizeau
Software Developer
PDFTron Systems Inc.
Reply all
Reply to author
Forward
0 new messages