7

关于 electron 无边框窗口拖动的问题

 3 years ago
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.
neoserver,ios ssh client

V2EX  ›  程序员

关于 electron 无边框窗口拖动的问题

  7075 · 7 小时 26 分钟前 · 816 次点击
有没有一个比较好的库或者源码,可以实现非 css 样式方式的窗体的拖动呢(程序有多个窗体)?
需要至少可以兼容 win,macos
10 条回复    2021-06-03 10:16:14 +08:00

lswl66

lswl66   7 小时 25 分钟前 via iPhone

哈哈哈你之前是怎么拖动的?

7075

7075   7 小时 15 分钟前

@lswl66 css 样式,问题多的一批啊

yangheng4922

yangheng4922   7 小时 8 分钟前

那就监听鼠标拖动 js 控制窗口位置

7075

7075   7 小时 3 分钟前

@leohxj 嗯嗯,已经实现了无边框窗体,主要是不想用他自带的 css 样式实现拖动。希望窗口所有位置可以拖动,又不影响所有的 dom 元素的事件响应( css 样式会干扰页面交互事件)。

7075

7075   7 小时 3 分钟前

@yangheng4922 有没有现成的库或者源码?~

yangheng4922

yangheng4922   6 小时 57 分钟前

@7075 #6 没有
全局 addEventListener 一下鼠标事件 setPosition 移动窗口

xudaolong

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
})
}
})
```

7075

7075   6 小时 46 分钟前

thanks ! i'll give it a try !

7075

7075   6 小时 45 分钟前

@xudaolong 多谢,试试先~

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK