7
关于 electron 无边框窗口拖动的问题
source link: https://www.v2ex.com/t/781026
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
有没有一个比较好的库或者源码,可以实现非 css 样式方式的窗体的拖动呢(程序有多个窗体)?
需要至少可以兼容 win,macos
需要至少可以兼容 win,macos
10 条回复 • 2021-06-03 10:16:14 +08:00
7075 7 小时 3 分钟前
@leohxj 嗯嗯,已经实现了无边框窗体,主要是不想用他自带的 css 样式实现拖动。希望窗口所有位置可以拖动,又不影响所有的 dom 元素的事件响应( css 样式会干扰页面交互事件)。
xudaolong 6 小时 53 分钟前
类似代码,仅做参考
```
const getSize = debounce(() => {
const win = BrowserWindow.getFocusedWindow()
const [width, height] = win.getSize()
return { win, width, height }
}, 500, {
'leading': true,
'trailing': false
})
ipcMain.on('windowMoving', (e, { mouseX, mouseY }) => {
const { x, y } = screen.getCursorScreenPoint()
const { win, width, height } = getSize()
if (win && !win.isMaximized()) {
win.setBounds({
width,
height,
x: x - mouseX,
y: y - mouseY
})
}
})
```
```
const getSize = debounce(() => {
const win = BrowserWindow.getFocusedWindow()
const [width, height] = win.getSize()
return { win, width, height }
}, 500, {
'leading': true,
'trailing': false
})
ipcMain.on('windowMoving', (e, { mouseX, mouseY }) => {
const { x, y } = screen.getCursorScreenPoint()
const { win, width, height } = getSize()
if (win && !win.isMaximized()) {
win.setBounds({
width,
height,
x: x - mouseX,
y: y - mouseY
})
}
})
```
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK