I am currently working on positioning a contextMenu
using jQuery's jquery.ui.position
. The library I am utilizing for the ContextMenu
is available at this link:
https://swisnl.github.io/jQuery-contextMenu/demo
My approach to positioning the ContextMenu
is as follows:
$(document).ready(function() {
$.contextMenu({
selector: 'td[id="tdMenu"]',
trigger: 'left',
position: function (opt, x, y) {
try {
opt.$menu.position({
my: 'right top',
at: 'right bottom',
of: $("#tdDiv")
});
} catch (e) {
}
},
items: {
"0": { name: "Hi" },
}
});
});
The corresponding HTML structure is as follows:
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td id="tdDiv" style="background-color: yellow;">
Menu Div
</td>
</tr>
<tr>
<td id="tdMenu">
Click Here
</td>
</tr>
</table>
In Internet Explorer 11 (IE 11
), there is an issue where upon initial page load, the offset calculation by jquery.ui.position is incorrect when clicking on the td with the id tdMenu
. It only calculates correctly on the second click.
Upon investigation, it was discovered that within jquery.ui.position
, the offset calculation is done like this:
function getDimensions( elem ) {
var raw = elem[0];
return {
width: elem.outerWidth(),
height: elem.outerHeight(),
offset: elem.offset() // Wrong value on first click, correct on second.
};
}
An attempt to adjust by giving margin to the body as shown below:
<body style="margin: 0px;">
Removing the body margin resolves the issue and enables correct calculation even on the first click. However, removing the body margin is not an option. Can you suggest a workaround for this?