代码拉取完成,页面将自动刷新
const electron = require('@electron/remote')
const win = electron.getCurrentWindow();
// 鼠标按下还是抬起
let dragging = false;
let mouseX = 0;
let mouseY = 0;
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const dependency of ['chrome', 'node', 'electron']) {
replaceText(`${dependency}-version`, process.versions[dependency])
}
// 设置拖拽功能
const el = document.getElementById("imgAvatar");
el.addEventListener('mousedown', (e) => {
dragging = true;
const { pageX, pageY } = e;
mouseX = pageX;
mouseY = pageY;
});
})
// 鼠标抬起禁止拖拽
window.addEventListener('mouseup', () => {
dragging = false;
});
// 设置拖拽功能
window.addEventListener('mousemove', (e) => {
console.log(dragging)
if (dragging) {
const { pageX, pageY } = e;
const pos = win.getPosition();
pos[0] = pos[0] + pageX - mouseX;
pos[1] = pos[1] + pageY - mouseY;
win.setPosition(pos[0], pos[1], true);
}
});
// 设置指定区域的鼠标点击不穿透
window.addEventListener("mousemove", event => {
const el = document.getElementById("imgAvatar");
let flag = event.target === el;
if (!flag) {
win.setIgnoreMouseEvents(true, {forward: true});
} else {
win.setIgnoreMouseEvents(false);
}
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。