Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContextMenu appears with wrong position #502

Closed
element-code opened this issue Jan 20, 2017 · 2 comments
Closed

ContextMenu appears with wrong position #502

element-code opened this issue Jan 20, 2017 · 2 comments

Comments

@element-code
Copy link

element-code commented Jan 20, 2017

This hapens, when the body has max-width or somethink like that.
You need to calculate the position, relative to the offsetParent of the opt.$menu

QuickFix:
Rewrite the else on line 172:

position: function (opt, x, y) {
  var offset;
  // determine contextMenu position
  if (!x && !y) {
    opt.determinePosition.call(this, opt.$menu);
    return;
  } else if (x === 'maintain' && y === 'maintain') {
    // x and y must not be changed (after re-show on command click)
    offset = opt.$menu.position();
  } else {
    // x and y are given (by mouse event)
    offset = {top: y, left: x};
  }

to:

} else {
  // x and y are given (by mouse event)
  //but.. they are fixed x and y .. so we need to get the offsetParent's position to recalculate for our absolute position
  var offsetParentOffset = opt.$menu.offsetParent().offset();

  offset = {top: y - offsetParentOffset.top, left: x -offsetParentOffset.left};
}

as you can see, this fix is only used, when x and y are present from mouse event

EDIT:
changed from position() to offset()

@bbrala
Copy link
Member

bbrala commented Feb 19, 2017

I've tried to reproduce this, but i can't. Can you provide a test page or the HTML that breaks is here on maybe on jsfiddle?

@apptaro
Copy link

apptaro commented Mar 31, 2017

I have the same issue. Here's the test page:
https://jsfiddle.net/apptaro/rf765goz/

apptaro pushed a commit to apptaro/jQuery-contextMenu that referenced this issue Mar 31, 2017
@bbrala bbrala closed this as completed in 26f9306 Apr 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants