Skip to content
This repository was archived by the owner on Jul 22, 2023. It is now read-only.

Commit d8c4b70

Browse files
committed
Fixed a position issue for pages with scrollbars
1 parent 17427b4 commit d8c4b70

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

ctxmenu/ctxmenu.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
/* Do not edit these properties */
4141
position: absolute;
4242
z-index: 999;
43+
white-space:nowrap;
4344

4445
}
4546

ctxmenu/ctxmenu.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CtxMenuManagerClass {
6363

6464
// Open the menu
6565
menu._elementClicked = elementClicked;
66-
menu.openMenu(e.clientX, e.clientY);
66+
menu.openMenu(e.pageX, e.pageY);
6767
this._currentMenuVisible = menu;
6868

6969
// Add event listeners to close the window
@@ -226,12 +226,14 @@ class CtxMenuClass {
226226
// Set the screen position of the menu
227227

228228
// Ensure the menu doesn't go outside of the widnow
229-
if (x + this.menuContainer.offsetWidth > document.documentElement.clientWidth) {
230-
x = document.documentElement.clientWidth - this.menuContainer.offsetWidth - 1;
229+
const PageWidth = (document.documentElement.clientWidth + document.documentElement.scrollLeft);
230+
const PageHeight = (document.documentElement.clientHeight + document.documentElement.scrollTop);
231+
if (x + this.menuContainer.offsetWidth > PageWidth) {
232+
x = PageWidth - this.menuContainer.offsetWidth - 1;
231233
}
232234

233-
if (y + this.menuContainer.offsetHeight > document.documentElement.clientHeight) {
234-
y = document.documentElement.clientHeight - this.menuContainer.offsetHeight - 1;
235+
if (y + this.menuContainer.offsetHeight > PageHeight) {
236+
y = PageHeight - this.menuContainer.offsetHeight - 1;
235237
}
236238

237239
this.menuContainer.style.left = x + "px";

0 commit comments

Comments
 (0)