最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQueryUI: Place dialog box where mouse is clicked - Stack Overflow

programmeradmin4浏览0评论

I want to place the jquery dialog box where the user clicks on the screen.

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. I think that this is because the Y (height) position is the whole page position rather than the viewable area.

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?

Thanks.

I want to place the jquery dialog box where the user clicks on the screen.

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. I think that this is because the Y (height) position is the whole page position rather than the viewable area.

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?

Thanks.

Share Improve this question asked Aug 11, 2011 at 10:06 Mark WMark W 5,97417 gold badges62 silver badges100 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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');
});
发布评论

评论列表(0)

  1. 暂无评论