美文网首页
使Electron的webviw tag支持touch事件

使Electron的webviw tag支持touch事件

作者: 慢慢来lins | 来源:发表于2019-11-15 20:23 被阅读0次

    代码如下:

    
    <html>
    
    <head>
    
      <style type="text/css">
    
        * {
    
          margin: 0;
    
        }
    
      </style>
    
    </head>
    
    <body>
    
      <div style="position: relative; height: 100%; width: 100%;">
    
        <div style="position: absolute; width: 100%; height: 100%;    text-align: center;
    
        position: absolute;
    
        background-color: transparent;
    
        top: 0;
    
        left: 0;
    
        right: 0;
    
        bottom: 0;
    
        z-index: 1;">
    
          <webview style="width: 100%;
    
          height: 100%;
    
      " id="broswer" src="https://github.com">
    
          </webview>
    
        </div>
    
      </div>
    
      <script>
    
        var broswer = document.getElementById('broswer');
    
        broswer.addEventListener("dom-ready", () => {
    
          var webContents = broswer.getWebContents();
    
          webContents.debugger.attach('1.3');
    
          webContents.debugger.sendCommand('Emulation.setEmitTouchEventsForMouse', { enabled: true });
    
          webContents.debugger.sendCommand('Emulation.setTouchEmulationEnabled', {
    
            enabled: true,
    
            configuration: 'mobile',
    
          });
    
          webContents.openDevTools();
    
        });
    
      </script>
    
    </body>
    
    </html>
    
    

    其中,debugger用法,请参考官网地址:https://electronjs.org/docs/api/debugger

    相关文章

      网友评论

          本文标题:使Electron的webviw tag支持touch事件

          本文链接:https://www.haomeiwen.com/subject/yyzsictx.html