electron触摸屏缩放问题

在开发实践中发现,Electron打包的页面在双指触摸时会出现缩放的情况,以下是解决方案:

  • index.html 中 设置
  • 入口文件 index.js 中
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    ...
    //创建窗口
    mainWindow = new BrowserWindow({
    resizable: false, //不可缩放
    movable: false, //不可移动
    minimizable: DEBUG, //不可最小化
    closable: DEBUG, //不可关闭
    alwaysOnTop: !DEBUG, //永远最前
    fullscreen: true, //全屏
    frame: false, //无边框
    disableAutoHideCursor: true, //隐藏鼠标
    webPreferences:{
    nodeIntegration: true
    }
    });
    //禁止缩放
    let webContents = mainWindow.webContents;
    webContents.on('did-finish-load',() => {
    webContents.setZoomFactor(1);
    webContents.setVisualZoomLevelLimits(1,1);
    webContents.setLayoutZoomLevelLimits(0,0);
    });
    ...