当使用带有自定义激活菜单的 jQuery contextMenu 时,如何更改菜单的位置?
我使用 jquery contextMenu 作为下拉菜单。我并没有真正使用右键单击功能。相反,当我单击 div 标签时,菜单会出现在该 div 标签下方。我的工作就这么多。这是我基于代码的演示页面:http://medialize。 github.com/jQuery-contextMenu/demo/trigger-custom.html。
我想做的是偏移下拉菜单相对于其默认位置的位置。在上面链接的演示中,您将看到一个示例:
$('#activate-menu').on('click', function(e) {
e.preventDefault();
$('.context-menu-one').contextMenu({x: 100, y: 100});
})
这对我不起作用。菜单出现在浏览器的左上角,而不是偏离通常出现的位置。
感谢您的帮助!
布雷特
I'm using jquery contextMenu for drop down menus. I'm not really using the right-click functionality. Instead, when I click on a div tag, the menu appears below that div tag. That much I have working. Here's the demo page from which I based my code: http://medialize.github.com/jQuery-contextMenu/demo/trigger-custom.html.
What I'd like to do is offset the position of the drop down menu relative to its default position. In the demo linked to above, you'll see that one example is:
$('#activate-menu').on('click', function(e) {
e.preventDefault();
$('.context-menu-one').contextMenu({x: 100, y: 100});
})
This hasn't worked for me. The menu appears way up at the top left of my browser instead of being offset from the position where it normally would appear.
Thanks for any help!
Bret
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不熟悉该插件,但听起来
x
和y
选项与文档相关(或者可能是由选择器识别的元素,< a href="http://medialize.github.com/jQuery-contextMenu/docs.html#show-trigger" rel="nofollow">文档似乎有点模糊)。您在点击时收到的事件对象具有pageX
和pageY
属性告诉您相对于文档点击发生的位置,因此只需添加这些属性即可,例如:偏移 100 像素可能有点多,但这就是原则。
I'm not familiar with that plug-in, but it sounds like the
x
andy
options are relative to the document (or possibly the element identified by the selector, the documentation seems a bit vague). The event object you receive on the click haspageX
andpageY
properties which tell you where the click occurred relative to the document, so just add to those, e.g.:Offsetting by 100 pixels may be a bit much, but that's the principle.