問題描述
我一直試圖在 false 上移動無框窗口,但現在我想通過拖動一個元素(標題欄)來移動 整個 窗口,我已經嘗試過 -webkit-app-region: drag;
但它似乎不起作用,我也嘗試過 https://www.npmjs.com/package/electron-drag 但它也不起作用.
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 -webkit-app-region: drag;
but it doesn't seem to work, I've also tried https://www.npmjs.com/package/electron-drag but it does't work either.
推薦答案
由于您的窗口是無框的,您可以使用屬性 -webkit-app-region
有效,即使您的 IDE 說它不是.出于用戶體驗的考慮,您應該禁止文本選擇并拖動標題欄內的按鈕.
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;
}
API 文檔也提到了這一點 https://github.com/electron/electron/blob/master/docs/api/frameless-window.md#draggable-region
The API documentation mentions this too https://github.com/electron/electron/blob/master/docs/api/frameless-window.md#draggable-region
這篇關于如何在不使用 -webkit-app-region 的情況下在 Electron 中移動無框窗口的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!