
1 lswl66 2021-06-03 09:36:04 +08:00 via iPhone 哈哈哈你之前是怎么拖动的? |
3 leohxj 2021-06-03 09:52:24 +08:00 |
4 yangheng4922 2021-06-03 09:52:54 +08:00 那就监听鼠标拖动 js 控制窗口位置 |
5 7075 OP @leohxj 嗯嗯,已经实现了无边框窗体,主要是不想用他自带的 css 样式实现拖动。希望窗口所有位置可以拖动,又不影响所有的 dom 元素的事件响应( css 样式会干扰页面交互事件)。 |
6 7075 OP @yangheng4922 有没有现成的库或者源码?~ |
7 yangheng4922 2021-06-03 10:04:17 +08:00 @7075 #6 没有 全局 addEventListener 一下鼠标事件 setPosition 移动窗口 |
8 xudaolong 2021-06-03 10:07:42 +08:00 类似代码,仅做参考 ``` 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 }) } }) ``` |
9 7075 OP thanks ! i'll give it a try ! |
11 codehz 2021-06-03 17:53:01 +08:00 不用那个样式的话会有很多边界问题要处理。。比如考虑下鼠标移动过快,超过窗口区域 还有用户预期的 aero 效果(指移动到屏幕边界的贴合效果,分屏操作等)这些都是很难在纯粹的 js 层面解决的。。。 |