当前位置: 首页 > news >正文

宁波外贸网站开发南昌建设网站公司

宁波外贸网站开发,南昌建设网站公司,网站建设费可以走办公费吗,wordpress 煎蛋评论最近使用了electron框架,发现如果自定义拖动是比较实用的;特别是定制化比较高的项目,如果单纯的使用-webkit-app-region: drag;会让鼠标事件无法触发; 过程中发现问题: 1.windows缩放不是100%后设置偏移界面会缩放,感觉像吹起的气…

最近使用了electron框架,发现如果自定义拖动是比较实用的;特别是定制化比较高的项目,如果单纯的使用-webkit-app-region: drag;会让鼠标事件无法触发;

过程中发现问题:

1.windows缩放不是100%后设置偏移界面会缩放,感觉像吹起的气球;

2.单纯的添加css;-webkit-app-region: drag; 会让鼠标事件无法触发;

封装核心方法
import { screen  } from 'electron'
/* 自定义窗口移动 */
export class AzCustomWindowMove {// 是否开启isOpen: boolean;// 传入要处理的窗口win: any;// 窗口偏移winStartPosition: {x: number, y: number, width: number, height: number,}// 现在鼠标所在位置startPosition: {x: number, y: number,}constructor() {this.isOpen = false;this.win = null;this.winStartPosition = {x: 0,y: 0,width: 0,height: 0,}this.startPosition = {x: 0,y: 0,}}init(win: any) {this.win = win;}start() {this.isOpen = true;// 获取当前窗口偏移[x, y]const winPosition = this.win.getPosition();// 获取当前缩放[width, height]const winSize = this.win.getSize();this.winStartPosition.x = winPosition[0];this.winStartPosition.y = winPosition[1];this.winStartPosition.width = winSize[0];this.winStartPosition.height = winSize[1];// 获取鼠标绝对位置const mouseStartPosition = screen.getCursorScreenPoint();this.startPosition.x = mouseStartPosition.x;this.startPosition.y = mouseStartPosition.y;// 开启刷新this.move();}move() {if (!this.isOpen) {return;};console.log('this.win.isDestroyed()', this.win.isDestroyed(), this.win.isFocused());// 如果窗口已销毁if (this.win.isDestroyed()) {this.end();return;}// 判断窗口是否聚焦if (!this.win.isFocused()) {this.end();return;}const cursorPosition = screen.getCursorScreenPoint();const x = this.winStartPosition.x + cursorPosition.x - this.startPosition.x;const y = this.winStartPosition.y + cursorPosition.y - this.startPosition.y;// this.win.setPosition(120, 120, false);// this.win.setBounds({x: 120, y: 120})// 更新位置的同时设置窗口原大小, windows上设置=>显示设置=>文本缩放 不是100%时,窗口会拖拽放大this.win.setBounds({x: x,y: y,width: this.winStartPosition.width,height: this.winStartPosition.height,})setTimeout(() => {this.move();}, 20)}end() {this.isOpen = false;}
}
在main.js中引入
import { AzCustomWindowMove } from './util';/* new 自定义窗口移动 */
const CustomWindowMove = new AzCustomWindowMove();// 创建一个窗口
const mainWindow = new BrowserWindow({frame: false,webPreferences: {preload: join(__dirname, '../preload/index.js'),sandbox: false}
})// 将窗口传进去
CustomWindowMove.init(mainWindow)// 通信监听
ipcMain.on("Main_Window_Operate", (event, info) => {    const operateEvent = info.event || '';switch(operateEvent) {// 拖拽窗口-开始case 'homeDragWindowStart':{/*如果别的窗口也想复用这个自定义拖拽方法可以这么用;const webContents = event.sender;const win = BrowserWindow.fromWebContents(webContents);CustomWindowMove.init(win);CustomWindowMove.start();*/CustomWindowMove.start();}break;// 拖拽窗口-结束case 'homeDragWindowEnd':{CustomWindowMove.end();}break;default:break;}})
preload.ts 预加载脚本
import { contextBridge, ipcRenderer } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
...contextBridge.exposeInMainWorld('customAPI', {/***  发布main窗口操作消息* @param info {type: 操作类型, data: 参数}*/publishMainWindowOperateMessage: (info: {event: string, data: {}}) => {ipcRenderer.send("Main_Window_Operate", info);} 
})
...
React绑定事件
 const handleMouseDown = (e) => {(window as any).customAPI.publishMainWindowOperateMessage({event: 'homeDragWindowStart'});
}
const handleMouseUp = (e) => {(window as any).customAPI.publishMainWindowOperateMessage({event: 'homeDragWindowEnd'});
}
/*第二个思路, 当按下后监听document的事件*/
const handleMouseDown = (e) => {// 通知开始(window as any).customAPI.publishMainWindowOperateMessage({event: 'homeDragWindowStart'});// 鼠标抬起document.onmouseup = function () {document.onmousemove = null;document.onmouseup = null;document.onselectstart = null;// 通知结束(window as any).customAPI.publishMainWindowOperateMessage({event: 'homeDragWindowEnd'});}
}
<divonMouseDown={handleMouseDown} onMouseUp={handleMouseUp} 
>自定义窗口移动</div>
http://www.15wanjia.com/news/184697.html

相关文章:

  • kangle搭建wordpress聊城哪里做优化网站
  • 正能量网站推荐免费下载王通seo赚钱培训
  • seo做的好的网站 知乎简单的网页设计模板
  • 工信部 网站开发设计师东莞建站公司速推全网天下首选
  • 访问国外网站的软件哈尔滨网站建设培训
  • 做gif表情包的网站如何创建网址免费注册
  • 肇庆企业做网站银川seo公司
  • 怎么做跳转不影响原网站排名上海比较出名的互联网公司
  • 长宁区网站制作设计公司建设一个网站
  • 百度推广 帮做网站吗手机建网站需要多少钱
  • 沧州企业网站制作的网站推广方案中评价效果是指
  • 重庆广告公司网站建设叶梓 wordpress 主题
  • 青岛菜西有做网站的吗南通市港闸区城乡建设局网站
  • 亚马逊雨林十大恐怖动物网站优化千牛帮
  • 网站域名注册商泰安房价走势图
  • 移动网站建设推荐电商网站首页代码
  • 宠物网站建设方案成都科技网站建设热
  • 千万别去电商公司上班windows清理优化大师
  • 武宁县建设工程招标公告门户网站用表格做的网站
  • 网站推广需要几个人做工作室网站需要备案吗
  • 创客网站建设集团网站制作方案ppt
  • 网站购买后如何做wordpress 4.8.4 漏洞
  • 网站建设注意哪些事项网站在线支付功能
  • 做网站好的框架新建一个网站需要多少钱
  • ionic 做网站长沙网站推广优化
  • 企业做网站需要的资料建站开发
  • 网站模板 酒店 中文网站设计电商运营
  • 网站和平台是一个意思吗广东省建设厅信息网
  • 厦门网站设计排行超融合系统
  • 域名销售网站徐州模板自助建站