首页 > 解决方案 > 电子“-webkit-app-region:拖动”在 BrowserView 内容中不起作用

问题描述

在我的 Electron 应用程序中,我正在创建一个BrowserWindow

let window = new BrowserView({
    title: "My App",
    frame: false,
    show: false
}

然后我正在加载BrowserView

let view = new BrowserView();
window.setBrowserView(view);
view.setBounds({ x: 0, y: 0, width: window.getContentBounds().width, height: window.getContentBounds().height });
view.setAutoResize({ width: true, height: true});
view.webContents.loadURL("MY URL HERE");

在加载到的内容中BrowserView,我正在尝试创建一个自定义标题栏,并且我做了类似的事情:

<div id="windowBar">
    <div id="draggableArea">
        <div id="title"><span>My App</span></div>
        <div id="controls">
            <!-- The window controls to minimize/maximize/close the window here !-->
        </div>
    </div>
</div>

我想让它拖动整个 Electron 窗口,所以我添加了 CSS:

#windowBar {
    height: 30px;
    width: 100%;
    position: fixed;
}

#draggableArea {
    width: 100%;
    height: 100%;
    -webkit-app-region: drag;
}

#title {
    -webkit-app-region: drag;
    user-select: none;
}

#controls {
    -webkit-app-region: no-drag;
}

我无法从文档以及我在网上找到的所有其他内容中判断这是否应该有效。或者是否需要将标题栏的 HTML 直接加载到其中BrowserWindow才能正常工作?

标签: javascriptelectron

解决方案


推荐阅读