Improve use of clientX instead of offsetX.
This commit is contained in:
parent
fc582df257
commit
ab78385833
1 changed files with 8 additions and 9 deletions
|
@ -11,18 +11,17 @@ function hide_open_menus()
|
||||||
}
|
}
|
||||||
|
|
||||||
contextmenus.show_menu =
|
contextmenus.show_menu =
|
||||||
function show_menu(event, element)
|
function show_menu(event, menu)
|
||||||
{
|
{
|
||||||
contextmenus.hide_open_menus();
|
contextmenus.hide_open_menus();
|
||||||
console.log(event);
|
menu.classList.add("open_contextmenu");
|
||||||
element.classList.add("open_contextmenu");
|
|
||||||
const html = document.documentElement;
|
const html = document.documentElement;
|
||||||
const over_right = Math.max(0, event.clientX + element.offsetWidth - html.clientWidth);
|
const over_right = Math.max(0, event.clientX + menu.offsetWidth - html.clientWidth);
|
||||||
const over_bottom = Math.max(0, event.clientY + element.offsetHeight - html.clientHeight);
|
const over_bottom = Math.max(0, event.clientY + menu.offsetHeight - html.clientHeight);
|
||||||
const left = event.target.offsetLeft + event.offsetX - over_right;
|
const left = event.pageX - over_right;
|
||||||
const top = event.target.offsetTop + event.offsetY - over_bottom;
|
const top = event.pageY - over_bottom;
|
||||||
element.style.left = left + "px";
|
menu.style.left = left + "px";
|
||||||
element.style.top = top + "px";
|
menu.style.top = top + "px";
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_pageload()
|
function on_pageload()
|
||||||
|
|
Loading…
Reference in a new issue