How do I move a frameless window in Electron without using -webkit-app-region

后端 未结 2 1857
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-02 14:49

I\'ve been trying to move a frameless window on false but now I want to move the whole window just by dragging one element (the title bar), I\'ve tried -w

相关标签:
2条回答
  • 2021-02-02 15:03

    First create your app window with the frame option set to false on your main.js file:

    mainWindow = new BrowserWindow({
    ...
    frame: false
    })
    

    Then in your renderer.js file create an HTML element (Ex. ) with the -webkit-app-region propperty set to drag.

    var windowTopBar = document.createElement('div')
    windowTopBar.style.width = "100%"
    windowTopBar.style.height = "32px"
    windowTopBar.style.backgroundColor = "#000"
    windowTopBar.style.position = "absolute"
    windowTopBar.style.top = windowTopBar.style.left = 0
    windowTopBar.style.webkitAppRegion = "drag"
    document.body.appendChild(windowTopBar)
    
    0 讨论(0)
  • 2021-02-02 15:11

    Since your windows are frameless you can use the property -webkit-app-region which is valid even though your IDE says it's not. You just should forbid the text selection and drag on buttons inside of your title bar too out of UX concerns.

    .titlebar {
      -webkit-user-select: none;
      -webkit-app-region: drag;
    }
    
    .titlebar-button {
      -webkit-app-region: no-drag;
    }
    

    The API documentation mentions this too https://github.com/electron/electron/blob/master/docs/api/frameless-window.md#draggable-region

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