简体   繁体   English

JQueryUI:单击鼠标的位置对话框

[英]JQueryUI: Place dialog box where mouse is clicked

I want to place the jquery dialog box where the user clicks on the screen.我想将 jquery 对话框放置在用户单击屏幕的位置。

so far I have:到目前为止,我有:

$("#something").click(function(e){
    $("#myDialog").dialog( "option", "position", [e.pageX,e.pageY]);
    $("#myDialog").dialog('open');
});

But this doesnt work due to some page scrolling issues.但是由于某些页面滚动问题,这不起作用。 I suspect it would work if I didnt have to scroll the page down to get to the element with id="something" that I click.我怀疑如果我不必向下滚动页面以到达我单击的带有 id="something" 的元素,它会起作用。 I think that this is because the Y (height) position is the whole page position rather than the viewable area.我认为这是因为 Y(高度)position 是整个页面 position 而不是可视区域。

Is there a way to either grab the viewable area XY co-ords or calculate the size of the viewable area and do some funky maths to correct the page XY co-ords?有没有办法获取可视区域 XY 坐标或计算可视区域的大小并做一些时髦的数学来纠正页面 XY 坐标?

Thanks.谢谢。

Try this:尝试这个:

$("#something").click(function(e)
{
    var x =e.pageX -$(document).scrollLeft();
    var y =e.pageY -$(document).scrollTop();
    $("#myDialog").dialog( "option", "position", [x,y]);
    $("#myDialog").dialog('open');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM