Disable pinch zoom in webkit (or electron)

后端 未结 9 2192
北荒
北荒 2020-12-29 02:23

Is there any way to disable pinch zoom in an electron app?

I can\'t get it to work from inside the web-view with normal javascript methods as described here: https:/

相关标签:
9条回答
  • 2020-12-29 02:50

    Answer from GitHub:

    "If you are looking for a way how to prevent zoom from main process, you can use:"

    const webContents = mainWindow.webContents;
    webContents.on('did-finish-load', () => {
      webContents.setZoomFactor(1);
      webContents.setVisualZoomLevelLimits(1, 1);
      webContents.setLayoutZoomLevelLimits(0, 0);
    });
    

    mainWindow is variable where you have new BrowserWindow, e.g.:

    const mainWindow = new BrowserWindow({
      width: 440,
      height: 750,
      // ...
    });
    
    const webContents = mainWindow.webContents;
    webContents.on("did-finish-load", () => {
      webContents.setZoomFactor(1);
      webContents.setVisualZoomLevelLimits(1, 1);
      webContents.setLayoutZoomLevelLimits(0, 0);
    });
    
    0 讨论(0)
  • 2020-12-29 02:58

    I searched so long and hard for a simple solution to this problem with no avail...but later I discovered a plugin called fullpage.js that was able to prevent pinch zoom while still allowing touch gestures. Through the process of js/css elimination, I discovered a very simple solution:

    touch-action: none;
    

    Adding this to my full page element successfully prevented pinch zoom but allowed me to scale fabricjs objects with pinching. Hooray !

    0 讨论(0)
  • 2020-12-29 02:58

    meta tag should have worked. Try using the minimum-scale=1.0

    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=no">
    

    And if it also not works then add both the minimum and maximum scale

    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    

    P.S. : It will disable zooming on mobile phones only.

    0 讨论(0)
提交回复
热议问题