mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-10 06:10:50 +08:00
Add a menu that can be moved from the main page
This commit is contained in:
parent
27693b3e6c
commit
f53af22391
37
web/extensions/menuMove.js
Normal file
37
web/extensions/menuMove.js
Normal file
@ -0,0 +1,37 @@
|
||||
import { app } from "../scripts/app.js";
|
||||
|
||||
const ext = {
|
||||
name: "Comfy.MenuMove",
|
||||
|
||||
async init(app) {
|
||||
let menuContainerRect = { f: false, x: 0, y: 0 };
|
||||
|
||||
document.addEventListener("mousemove", (event) => {
|
||||
if (menuContainerRect.f) {
|
||||
localStorage[`${this.name}.X`] = menu.style.left = `${((event.x - menuContainerRect.x) / window.innerWidth) * 100}%`;
|
||||
localStorage[`${this.name}.Y`] = menu.style.top = `${((event.y - menuContainerRect.y) / window.innerHeight) * 100}%`;
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("mouseup", _ => {
|
||||
menuContainerRect.f = false;
|
||||
}, true);
|
||||
|
||||
const menu = document.querySelector("div.comfy-menu");
|
||||
|
||||
menu.onmousedown = event => {
|
||||
if (menu === event.toElement) {
|
||||
menuContainerRect.f = true;
|
||||
menuContainerRect.x = event.offsetX;
|
||||
menuContainerRect.y = event.offsetY;
|
||||
}
|
||||
}
|
||||
|
||||
menu.style.left = localStorage[`${this.name}.X`] ?? "";
|
||||
menu.style.top = localStorage[`${this.name}.Y`] ?? "50%";
|
||||
|
||||
console.log("start Menu Moving!");
|
||||
},
|
||||
};
|
||||
|
||||
app.registerExtension(ext);
|
||||
Loading…
Reference in New Issue
Block a user